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

issubclass

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

Project details


Download files

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

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page