{"id":16854580,"url":"https://github.com/bswck/class_singledispatch","last_synced_at":"2025-04-05T10:43:41.549Z","repository":{"id":212892730,"uuid":"683667451","full_name":"bswck/class_singledispatch","owner":"bswck","description":"A singledispatch() for arguments that are classes annotated as specific types.","archived":false,"fork":false,"pushed_at":"2024-04-21T23:08:36.000Z","size":220,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-22T17:25:56.445Z","etag":null,"topics":["python","singledispatch"],"latest_commit_sha":null,"homepage":"https://class-singledispatch.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bswck.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":"bswck"}},"created_at":"2023-08-27T10:17:22.000Z","updated_at":"2024-04-21T23:07:09.000Z","dependencies_parsed_at":"2024-04-13T16:34:40.717Z","dependency_job_id":"08b30ba2-09e1-4d1b-84f5-15da0e5ecb60","html_url":"https://github.com/bswck/class_singledispatch","commit_stats":null,"previous_names":["bswck/class_singledispatch"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bswck%2Fclass_singledispatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bswck%2Fclass_singledispatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bswck%2Fclass_singledispatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bswck%2Fclass_singledispatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bswck","download_url":"https://codeload.github.com/bswck/class_singledispatch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325648,"owners_count":20920713,"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":["python","singledispatch"],"created_at":"2024-10-13T13:56:02.546Z","updated_at":"2025-04-05T10:43:41.526Z","avatar_url":"https://github.com/bswck.png","language":"Python","funding_links":["https://github.com/sponsors/bswck"],"categories":[],"sub_categories":[],"readme":"# \u003cdiv align=\"center\"\u003eclass_singledispatch\u003cbr\u003e[![skeleton](https://img.shields.io/badge/0.0.2rc–224–ge16504a-skeleton?label=%F0%9F%92%80%20skeleton-ci/skeleton-python\u0026labelColor=black\u0026color=grey\u0026link=https%3A//github.com/skeleton-ci/skeleton-python)](https://github.com/skeleton-ci/skeleton-python/tree/0.0.2rc-224-ge16504a) [![Supported Python versions](https://img.shields.io/pypi/pyversions/class-singledispatch.svg?logo=python\u0026label=Python)](https://pypi.org/project/class-singledispatch/) [![Package version](https://img.shields.io/pypi/v/class-singledispatch?label=PyPI)](https://pypi.org/project/class-singledispatch/)\u003c/div\u003e\n\n[![Tests](https://github.com/bswck/class_singledispatch/actions/workflows/test.yml/badge.svg)](https://github.com/bswck/class_singledispatch/actions/workflows/test.yml)\n[![Coverage](https://coverage-badge.samuelcolvin.workers.dev/bswck/class_singledispatch.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/class_singledispatch)\n[![Documentation Status](https://readthedocs.org/projects/class-singledispatch/badge/?version=latest)](https://class-singledispatch.readthedocs.io/en/latest/?badge=latest)\n\nA [``singledispatch()``](https://docs.python.org/3/library/functools.html#functools.singledispatch) for arguments that are classes annotated as specific types.\n\nInspired by https://github.com/python/cpython/issues/100623.\n\n# A Simple Example\nWhile `functools.singledispatch` examines the class of the first user argument,\n`class_singledispatch` uses the first argument as the class itself and performs\nthe same task with it as `functools.singledispatch`.\n\n```python\nfrom class_singledispatch import class_singledispatch\n\n\nclass T:\n    pass\n\n\nclass OtherT:\n    pass\n\n\n@class_singledispatch\ndef on_class(cls: type[T], /) -\u003e None:\n    print(\"T!\")\n\n\n@on_class.register\ndef on_other_class(cls: type[OtherT], /) -\u003e None:\n    print(\"OtherT!\")\n\n\n# Useful for \u003c3.10 without eval_type_backport -- pass the class to the decorator\n# not to use the annotation from the function for the targeted class resolution\n@on_class.register(SomeOtherT)\ndef on_some_other_class(cls: type[SomeOtherT], /) -\u003e None:\n    print(\"SomeOtherT!\")\n\n\non_class(T)  # T!\non_class(OtherT)  #  OtherT!\non_class(SomeOtherT)  #  SomeOtherT!\n```\n\n# Installation\nYou might simply install it with pip:\n\n```shell\npip install class-singledispatch\n```\n\u003e [!Note]\n\u003e `class-singledispatch` supports modern type hinting.\u003cbr/\u003e\n\u003e To use [PEP 585](https://peps.python.org/pep-0585/)\n\u003e or [PEP 604](https://peps.python.org/pep-0604/) annotations on Python \u003c3.10, install\n\u003e `class-singledispatch[modern-type-hints]`.\n\nIf you use [Poetry](https://python-poetry.org/), then you might want to run:\n\n```shell\npoetry add class-singledispatch\n```\n\n## For Contributors\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)](https://github.com/pre-commit/pre-commit)\n\u003c!--\nThis section was generated from skeleton-ci/skeleton-python@0.0.2rc-224-ge16504a.\nInstead of changing this particular file, you might want to alter the template:\nhttps://github.com/skeleton-ci/skeleton-python/tree/0.0.2rc-224-ge16504a/project/README.md.jinja\n--\u003e\n\u003e [!Note]\n\u003e If you use Windows, it is highly recommended to complete the installation in the way presented below through [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install).\n1.  Fork the [class_singledispatch repository](https://github.com/bswck/class_singledispatch) on GitHub.\n\n1.  [Install Poetry](https://python-poetry.org/docs/#installation).\u003cbr/\u003e\n    Poetry is an amazing tool for managing dependencies \u0026 virtual environments, building packages and publishing them.\n    You might use [pipx](https://github.com/pypa/pipx#readme) to install it globally (recommended):\n\n    ```shell\n    pipx install poetry\n    ```\n\n    \u003csub\u003eIf you encounter any problems, refer to [the official documentation](https://python-poetry.org/docs/#installation) for the most up-to-date installation instructions.\u003c/sub\u003e\n\n    Be sure to have Python 3.8 installed—if you use [pyenv](https://github.com/pyenv/pyenv#readme), simply run:\n\n    ```shell\n    pyenv install 3.8\n    ```\n\n1.  Clone your fork locally and install dependencies.\n\n    ```shell\n    git clone https://github.com/your-username/class_singledispatch path/to/class_singledispatch\n    cd path/to/class_singledispatch\n    poetry env use $(cat .python-version)\n    poetry install\n    ```\n\n    Next up, simply activate the virtual environment and install pre-commit hooks:\n\n    ```shell\n    poetry shell\n    pre-commit install\n    ```\n\nFor more information on how to contribute, check out [CONTRIBUTING.md](https://github.com/bswck/class_singledispatch/blob/HEAD/CONTRIBUTING.md).\u003cbr/\u003e\nAlways happy to accept contributions! ❤️\n\n# Legal Info\n© Copyright by Bartosz Sławecki ([@bswck](https://github.com/bswck)).\n\u003cbr /\u003eThis software is licensed under the terms of [MIT License](https://github.com/bswck/class_singledispatch/blob/HEAD/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbswck%2Fclass_singledispatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbswck%2Fclass_singledispatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbswck%2Fclass_singledispatch/lists"}