Python Slots Inheritance
Python In Greek mythology, Python is the name of a a huge serpent and sometimes a dragon. Python had been killed by the god Apollo at Delphi. Python was created out of the slime and mud left after the great flood. He was appointed by Gaia (Mother Earth) to guard the oracle of Delphi, known as Pytho. Python Inheritance Inheritance allows us to define a class that inherits all the methods and properties from another class. Browse other questions tagged python inheritance slots or ask your own question. The Overflow Blog The Loop: Adding review guidance to the help center. Podcast 288: Tim Berners-Lee wants to put you in a pod. Featured on Meta A big thank you, Tim Post “Question closed” notifications experiment results and graduation. To have attributes named in slots to actually be stored in slots instead of a dict, a class must inherit from object. To prevent the creation of a dict, you must inherit from object and all classes in the inheritance must declare slots and none of them can have a 'dict' entry.
Latest versionReleased:
Decorator to add __slots__ in dataclasses
Project description
Decorator for adding slots
Python3.7 provides dataclasses module for faster class creation (PEP 557).Unfortunately there's no support for __slots__. If you want to create more memory efficient instances, you need todo it by yourself or use dataslots.dataslots decorator.
Usage
Simple example
Inheritance
As described in docs, in derived class __dict__ is created, because base class does not have __slots__.Slots are created from all defined properties (returned by dataclasses.fields() function).
Dynamic assignment of new variables
Weakref
Read-only class variables
With __slots__ it's possible to define read-only class variables. When using dataclasses you cannot provide typefor attribute or use typing.ClassVar to declare one.
Pickling frozen dataclass
Because of an issue 36424 you need custom __setstate__ method. In dataslots there isimplemented default version and it is used if decorated class has no __getstate__ and __setstate__ function declared.
More about __slots__
Release historyRelease notifications RSS feed
1.0.2
1.0.2rc2 pre-release
1.0.1
1.0.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size dataslots-1.0.2-py2.py3-none-any.whl (4.1 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes |
Filename, size dataslots-1.0.2.tar.gz (7.5 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for dataslots-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 4fe302ab59c86e01a4fafe516776a198cd8a42dc696dcc9d525e2ec8ee0fe773 |
MD5 | aa8075201eba64938a16361e741a901b |
BLAKE2-256 | b2b22f9f4ea849a076effa673dd9b7e67bedb9358ad0875c30cd4ae0ad6298bc |
Python Inheritance Multiple
CloseHashes for dataslots-1.0.2.tar.gz
Python Slots Inheritance Money
Algorithm | Hash digest |
---|---|
SHA256 | 0dfc4d12aab104b00ddb88a585c0a2227bbb9bd19c785dc8068b43eb0d6009e1 |
MD5 | 656b169564c8623fe9a97aa5f25df7fd |
BLAKE2-256 | a81ca45405ae05d585b786e1819a3406310a097ffd7bf5f104e7c78e63cb86a8 |
Python Function Inheritance
|