Metadata-Version: 2.1
Name: inheritance-dict
Version: 0.2.0.0
Summary: Looking for the value associated with the most specific super type in the dictionary
Home-page: https://github.com/hapytex/inheritance_dict/
Author: Willem Van Onsem
Author-email: Willem Van Onsem <yourfriends@hapytex.eu>
License: BSD-3-Clause
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE

# `inheritance_dict`

[![PyPI - Version](https://img.shields.io/pypi/v/inheritance_dict)](https://pypi.org/project/inheritance_dict/)
[![Coverage](https://img.shields.io/coverallsCoverage/github/hapytex/inheritance_dict)](https://coveralls.io/github/hapytex/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.
