{"id":30034207,"url":"https://github.com/stannielson/python-disinheritance","last_synced_at":"2025-10-24T13:10:51.788Z","repository":{"id":303859936,"uuid":"1016767538","full_name":"stannielson/Python-Disinheritance","owner":"stannielson","description":"Direct management of inherited methods/attributes in subclassed object types","archived":false,"fork":false,"pushed_at":"2025-07-09T19:12:00.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-10T04:51:47.241Z","etag":null,"topics":["decorator","disinheritance","inheritance","python","python-3","subclass"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stannielson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2025-07-09T13:47:53.000Z","updated_at":"2025-07-09T19:12:04.000Z","dependencies_parsed_at":"2025-07-10T04:54:59.565Z","dependency_job_id":"543f843b-c54c-49d7-b492-151ad3688715","html_url":"https://github.com/stannielson/Python-Disinheritance","commit_stats":null,"previous_names":["stannielson/python-disinheritance"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/stannielson/Python-Disinheritance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stannielson%2FPython-Disinheritance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stannielson%2FPython-Disinheritance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stannielson%2FPython-Disinheritance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stannielson%2FPython-Disinheritance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stannielson","download_url":"https://codeload.github.com/stannielson/Python-Disinheritance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stannielson%2FPython-Disinheritance/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269170586,"owners_count":24372066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["decorator","disinheritance","inheritance","python","python-3","subclass"],"created_at":"2025-08-06T23:12:49.485Z","updated_at":"2025-10-24T13:10:51.699Z","avatar_url":"https://github.com/stannielson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Disinheritance\n**_Disinheritance_** is the removal of inherited methods and attributes to prevent (i.e., \"disinherit\") unwanted capabilities in subclass types. Nominally, the approach to disinheritance in Python is by individually overriding the unwanted methods and attributes of a subclass. However, depending on the behavior of a parent class, this can be a laborious process, especially if a large amount of parent methods and attributes are unwanted. Another approach is by structuring types and subclassed types to ensure limited inheritance (e.g., with \"mixin\" use), which could require more complexity in creating appropriate subclass types.\n\nWhen other approaches are impractical, the `disinheritance` module may be a viable alternative. The `disinherit` decorator object automatically overrides unwanted inherited methods and attributes and prevents their use in subclass instances, except where specified as exemptions. Features of `disinherit` include:\n\n* Exemptions can be one or more type methods or even entire types in the subclass MRO (though exemptions are managed internally by type/containing type and declaration order)\n* Exemptions can be from anywhere in the MRO and will be applied to the subclass as overrides (unless already overriden in the subclass)\n* `dir()` call on a subclass instance will not include disinherited methods/attributes\n* Attempts at attribute retrieval of disinherited methods/attributes from an instance produce attribute errors\n* `help()` call on a subclass type will show disinherited methods/attributes as not implemented (i.e., as the `NotImplemented` singleton)\n* Invalid exemptions (i.e., types and type methods/attributes not in the MRO) are silently ignored\n* Subclass `__dir__` and `__getattribute__` methods are wrapped to both maintain original functionality and account for disinherited methods/attributes\n* Exemptions are explicitly specified using an `exempt` keyword argument for the sake of clarity and deliberate use in style\n* _Note: type attributes cannot be directly referenced for exemptions where an attribute does not back-reference the containing type_\n\n## Example:\n```\nfrom disinheritance import disinherit\n\n@disinherit()\nclass StrStandin(str):\n    \"\"\"object does not function like a regular str\"\"\"\n\n@disinherit(exempt=str.upper)\nclass StrUpper(str):\n    \"\"\"object allows upper method\"\"\"\n```\n\n```\n\u003e\u003e\u003e standin = StrStandin('hello, world!')\n\u003e\u003e\u003e upperonly = StrUpper('spam and eggs')\n```\n\n```\n\u003e\u003e\u003e dir(standin)\n['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__format__',\n'__getattribute__', '__getstate__', '__hash__', '__init__', '__init_subclass__',\n'__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',\n'__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']\n```\n\n```\n\u003e\u003e\u003e standin.upper()\nTraceback (most recent call last):\n  File \"\u003cpyshell#87\u003e\", line 1, in \u003cmodule\u003e\n    value.upper()\n  File \".../disinheritance.py\", line 188, in __getattribute__\n    raise error\nAttributeError: 'StrStandin' object has no attribute 'upper'\n```\n\n```\n\u003e\u003e\u003e upperonly.upper()\n'SPAM AND EGGS'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstannielson%2Fpython-disinheritance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstannielson%2Fpython-disinheritance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstannielson%2Fpython-disinheritance/lists"}