Questions tagged [slots]

`__slots__` is a python language feature to reduce size of object instances by dropping the builtin dictionary every python instance normally features in order to support dynamic assignment of attributes and replacing it with a fixed set of attributes (the 'slots').

__slots__ is a python language feature to reduce size of object instances by dropping the builtin dictionary every python instance normally features in order to support dynamic assignment of attributes and replacing it with a fixed set of attributes (the 'slots'). See: https://docs.python.org/2/reference/datamodel.html#slots

306 questions
7
votes
1 answer

Attribute access in Python: first slots, then __dict__?

In the example below, attribute x is accessed from the slots of the object even though x is present in __dict__ (this is not a typical or probably useful case, but I'm curious): >>> class C(object): ... __slots__ = 'x' ... >>> class…
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
6
votes
0 answers

What are the motivations for this use of `__slots__`?

Working with Sanic (async web framework in Python), I was trying to add custom data to a request: request.user = 'A nice user' But I was not able to, request is of type Request and does not allow this. Looking at the source code for the Request…
ldirer
  • 6,606
  • 3
  • 24
  • 30
6
votes
1 answer

Why can't nonempty slots be used with int, tuple, bytes subclasses?

This is explicitly documented in the reference manual: Nonempty _slots_ does not work for classes derived from “variable-length” built-in types such as int, bytes and tuple. and it is the case, writing: class MyInt(int): __slots__ =…
Bob Holver
  • 277
  • 1
  • 9
6
votes
3 answers

Comprehensive guide on common lisp types

Maybe this question is too general, nevertheless i'll try: Is there any comprehensive guide on types in common lisp? I'm kind of confused about this subject: Why are non-primitive types declared in make-array's :element-type are promoted to t? Is…
leetwinski
  • 17,408
  • 2
  • 18
  • 42
6
votes
1 answer

cascades and signals / slots

I'm running around in circles about this. Just can't wrap my head around signals and slots. Just looking for some mechanism that can automatically update my UI when a signal in my C++ occurs. Example: I have two labels in Qml that have text:…
James Perih
  • 1,360
  • 1
  • 17
  • 19
6
votes
1 answer

Use S3 virtual class as slot of an S4 class, got error: got class "S4", should be or extend class "nls.lm"

R Version: R version 2.15.2 (2012-10-26) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) I want to make an S4 class that use the output object of the function of nls.lm (package: minpack.lm) as a slot: setOldClass("nls.lm") setClass ( …
tucano
  • 224
  • 2
  • 9
5
votes
1 answer

Vue3 Composition Api check for empty slot

First project with Vue3, trying to determine if a named slot has content supplied on a given page. In my template I have this:
In my code I have the…
TheRealPapa
  • 4,393
  • 8
  • 71
  • 155
5
votes
1 answer

RASA Story w/ Slots

Can someone clarify for me with Rasa stories involving slots: ## story with email * intent_request_email - utter_request_email * inform_email {"email":"example@example.com"} - slot {"email":"example@example.com"} - utter_thanks In the…
Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88
5
votes
1 answer

Plot start-end time slots - matplotlib python

I'm trying to plot time slots. I have two ndarrays of 'start' and 'end' points. I want to draw it as chunks on a figure. Keep in mind that the chunks are not consecutive and there are gaps between the slots. Until now I have tried to use…
RefiPeretz
  • 543
  • 5
  • 19
4
votes
1 answer

pyQt signals/slots with QtDesigner

I'm trying to write a program that will interact with QGraphicsView. I want to gather mouse and keyboard events when the happen in the QGraphicsView. For example, if the user clicks on the QGraphicsView widget I will get the mouse position,…
Jeff
  • 6,932
  • 7
  • 42
  • 72
4
votes
3 answers

How to use v-model on a slot in vue 3?

I am trying to find a way to use a model component I made but with the ability to close the model from one of the slots. I can pass data to the slot but not with v-model and dont believe I can change the slot prop to close the model open…
Jordan
  • 391
  • 5
  • 17
4
votes
0 answers

Why does __class__ assignment work when classes have different __slots__?

From the Python language documentation: __class__ assignment works only if both classes have the same __slots__. So this is expected: >>> class A: __slots__ = ('x',) ... >>> class B(A): __slots__ = ('y',) ... >>> class C: __slots__ = ('x',…
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67
4
votes
2 answers

How can I force subclasses to have __slots__?

I have a class with __slots__: class A: __slots__ = ('foo',) If I create a subclass without specifying __slots__, the subclass will have a __dict__: class B(A): pass print('__dict__' in dir(B)) # True Is there any way to prevent B from…
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
4
votes
1 answer

How do the __slot__ descriptors work in python?

I know what __slots__ does and what it's supposed to be used for. However I have not found a comprehensive answer as to how the underlaying mechanisms of the member descriptor created using __slots__ works. Where are the object-level values…
Exa
  • 185
  • 12
4
votes
1 answer

custom __dir__() returns list of attributes sorted alphabetically

I have a custom __dir__ implementation in my base class which is supposed to return a list of all user-defined __slots__ attributes. This is working, in general, but it appears to be doing a sort on the result before it returns, even though I did…
deepbrook
  • 2,523
  • 4
  • 28
  • 49
1 2
3
20 21