{"id":23507325,"url":"https://github.com/pj/hacky_python_typeclasses","last_synced_at":"2025-10-17T01:20:27.744Z","repository":{"id":32808095,"uuid":"36400713","full_name":"pj/hacky_python_typeclasses","owner":"pj","description":"Typeclasses for Python (badly)","archived":false,"fork":false,"pushed_at":"2015-05-27T22:54:13.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T19:14:49.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-27T22:54:03.000Z","updated_at":"2015-05-27T22:54:14.000Z","dependencies_parsed_at":"2022-09-01T03:10:42.328Z","dependency_job_id":null,"html_url":"https://github.com/pj/hacky_python_typeclasses","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pj%2Fhacky_python_typeclasses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pj%2Fhacky_python_typeclasses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pj%2Fhacky_python_typeclasses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pj%2Fhacky_python_typeclasses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pj","download_url":"https://codeload.github.com/pj/hacky_python_typeclasses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253768391,"owners_count":21961316,"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","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":[],"created_at":"2024-12-25T10:17:50.095Z","updated_at":"2025-10-17T01:20:22.688Z","avatar_url":"https://github.com/pj.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hacky typeclasses for Python\n\nBasically the idea is to use python decorators to fake Haskell typeclasses (badly).\n\nTo create a method for a typeclass:\n\n```python\nfrom typeclass import typemethod\n\nclass Show(object):\n    pass\n\n@typemethod(Show)\ndef show(val):\n    # If there is no default then just raise NotImplementedError()\n    return str(val)\n```\n\nTo create an instance:\n\n```python\nfrom typeclass import typeinstance\nimport show\n\nclass Something(object):\n    def __init__(self, a):\n        self.a = a\n\n@typeinstance(Something, show.show)\ndef show(val):\n    return \"Something: \" + str(val.a)\n```\n\nThen use it by importing the show method from the typeclass and ensuring that\nthe instance is loaded:\n\n```python\nfrom show import show\nfrom something import Something\n\nprint show(Something(42))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpj%2Fhacky_python_typeclasses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpj%2Fhacky_python_typeclasses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpj%2Fhacky_python_typeclasses/lists"}