Skip to main content

Support for multiple inheritance and __slots__

Project description

stupid

A stupid workaround when using multiple inheritance and __slots__

installation

pip install stupid

example

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. 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)
True

isinstance check also works.

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

Project details


Download files

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

Source Distribution

stupid-0.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

stupid-0.1-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page