inheritance_dict
inheritance_dict is a small package where one can map types to values. If one then performs a lookup, it walks down the Method Resolution Order (MRO) looking for a match, and thus returns the value associated with the most specific superclass of the type.
Example
Imagine the following inheritance dictionary:
from inheritance_dict import InheritanceDict
example = InheritanceDict({object: 1, int: 2})
now we can query it with:
example[object] # 1
example[int] # 2
example[bool] # 2
example[float] # 1
example[str] # 1
It thus for each type tries to find the value that is associated with the most specific key-value pair for that type.
The main application is making mappings between types. For example, in Django the mapping between model fields, and serializer fields, resource fields, etc. is often done through such pattern. We thus aim to encapsulate the logic.
The dictionary can also contain non-type items. For lookups with keys where the key is not a type, it will try to lookup the key, just like it normally does.
The package also provides a TypeConvertingInheritanceDict which will, if the key is not found, and the key is not a type itself, try a second time with the type of the object. So if we have:
from inheritance_dict import TypeConvertingInheritanceDict
example2 = TypeConvertingInheritanceDict({object: 1, int: 2})
we can query with:
example2['A'] # 1
example2[0+1j] # 1
example2[3] # 2
There are also Fallback variants of these like FallbackInheritanceDict and FallbackTypeConvertingInheritanceDict, which allow to query with a tuple of keys, like:
from inheritance_dict import FallbackInheritanceDict
example3 = FallbackInheritanceDict({object: 1, int: 2})
then one can query with:
example3[complex, int] # 1
example3[int, complex] # 2
Metadata
Release files for inheritance-dict 0.5.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| inheritance_dict-0.5.0.0.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| inheritance_dict-0.5.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / inheritance_dict-0.5.0.0.tar.gz
| Download URL | inheritance_dict-0.5.0.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d0bb71a3d9b18dcaf76d05befe1fa9348e3badd2b1a46b6ee91279cebd5ced2
|
|
BLAKE2b-256 checksum How to use checksums |
fb8c16cc1ede9cdb74c809e97f8e7240e4006acf2998a7a33d5467bf41c18c35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / inheritance_dict-0.5.0.0-py3-none-any.whl
| Download URL | inheritance_dict-0.5.0.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63b95a8aa703b2d843f60eb8522a63bc00a2c35c6a3ab38ae3a2eaac050131fc
|
|
BLAKE2b-256 checksum How to use checksums |
634667ff9e2cac4331ad3833fdfe9595a79d9e0aef3a7bb983c10b6160e2d380
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for inheritance-dict 0.5.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.