Skip to main content

Support for multiple inheritance and __slots__

Project description


A stupid workaround when using multiple inheritance and __slots__


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):

payload = ApiPayload("root", sha512()) 
payload = ApiPayload(name="root", access_code=sha512())

__slots__ are autogenerated and works with multiple inheritance as shown above. As __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)

isinstance check also works.

>>> isinstance(payload, User)
>>> isinstance(payload, AccessData)


>>> from stupid import StupidData
>>> class A(StupidData): pass
>>> class B(A): pass
>>> class C:pass
>>> issubclass(B, A)
>>> issubclass(B, C)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for stupid, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size stupid-1.1.0-py3-none-any.whl (3.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size stupid-1.1.0.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page