{"id":34041737,"url":"https://github.com/hapytex/inheritance_dict","last_synced_at":"2026-04-01T19:18:22.647Z","repository":{"id":310884058,"uuid":"1041647986","full_name":"hapytex/inheritance_dict","owner":"hapytex","description":"A simple dictionary in Python to walk over the __mro__ of a type to look for a match.","archived":false,"fork":false,"pushed_at":"2025-09-13T20:35:16.000Z","size":99,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-28T00:58:04.701Z","etag":null,"topics":["dictionary","inheritance","mro","type"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/inheritance-dict/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hapytex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":"https://www.buymeacoffee.com/hapytex"}},"created_at":"2025-08-20T19:57:05.000Z","updated_at":"2025-09-09T20:30:01.000Z","dependencies_parsed_at":"2025-08-20T21:15:41.028Z","dependency_job_id":"1f64cb9c-a143-40f7-8c28-c57cd3453e07","html_url":"https://github.com/hapytex/inheritance_dict","commit_stats":null,"previous_names":["hapytex/inheritance_dict"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hapytex/inheritance_dict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Finheritance_dict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Finheritance_dict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Finheritance_dict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Finheritance_dict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hapytex","download_url":"https://codeload.github.com/hapytex/inheritance_dict/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapytex%2Finheritance_dict/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dictionary","inheritance","mro","type"],"created_at":"2025-12-13T22:05:34.310Z","updated_at":"2026-04-01T19:18:22.642Z","avatar_url":"https://github.com/hapytex.png","language":"Python","funding_links":["https://www.buymeacoffee.com/hapytex"],"categories":[],"sub_categories":[],"readme":"# `inheritance_dict`\n\n[![PyPI - Version](https://img.shields.io/pypi/v/inheritance_dict)](https://pypi.org/project/inheritance_dict/)\n[![Coverage](https://img.shields.io/coverallsCoverage/github/hapytex/inheritance_dict)](https://coveralls.io/github/hapytex/inheritance_dict)\n\n\n`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.\n\n## Example\n\nImagine the following inheritance dictionary:\n\n```\nfrom inheritance_dict import InheritanceDict\n\nexample = InheritanceDict({object: 1, int: 2})\n```\n\nnow we can query it with:\n\n```\nexample[object]  # 1\nexample[int]     # 2\nexample[bool]    # 2\nexample[float]   # 1\nexample[str]     # 1\n```\n\nIt thus for each type tries to find the value that is associated with the most specific key-value pair for that type.\n\nThe 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.\n\nThe 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.\n\nThe 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:\n\n```\nfrom inheritance_dict import TypeConvertingInheritanceDict\n\nexample2 = TypeConvertingInheritanceDict({object: 1, int: 2})\n```\n\nwe can query with:\n\n```\nexample2['A']   # 1\nexample2[0+1j]  # 1\nexample2[3]     # 2\n```\n\nThere are also `Fallback` variants of these like `FallbackInheritanceDict` and `FallbackTypeConvertingInheritanceDict`, which allow to query with a tuple of keys, like:\n\n```\nfrom inheritance_dict import FallbackInheritanceDict\n\nexample3 = FallbackInheritanceDict({object: 1, int: 2})\n```\n\nthen one can query with:\n\n```\nexample3[complex, int]  # 1\nexample3[int, complex]  # 2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapytex%2Finheritance_dict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapytex%2Finheritance_dict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapytex%2Finheritance_dict/lists"}