Support for multiple inheritance and __slots__
A stupid workaround when using multiple inheritance and
pip install stupid
from hashlib import sha512 from stupid import StupidData class User(StupidData): name: str class AccessData(StupidData): access_code: sha512 class ApiPayload(User, AccessData): pass payload = ApiPayload("root", sha512()) payload = ApiPayload(name="root", access_code=sha512())
__slots__ are autogenerated and works with multiple inheritance as shown above.
__slots__ are present assigning new attributes is not allowed.
>>> payload = ApiPayload(name="root", access_code=sha512()) >>> payload.extra = 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'ApiPayload' object has no attribute 'extra'
It's also a dataclass.
>>> from dataclasses import is_dataclass >>> is_dataclass(ApiPayload) True
isinstance check also works.
>>> isinstance(payload, User) True >>> isinstance(payload, AccessData) True
>>> from stupid import StupidData >>> class A(StupidData): pass >>> class B(A): pass >>> class C:pass >>> >>> issubclass(B, A) True >>> issubclass(B, C) False
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|stupid-1.1.0-py3-none-any.whl (3.5 kB) Copy SHA256 hash SHA256||Wheel||py3|
|stupid-1.1.0.tar.gz (3.3 kB) Copy SHA256 hash SHA256||Source||None|