Skip to main content

singledispatch with support for type/class arguments

Project description

singledispatch-with-type-arg-support

Standalone "preview" of https://github.com/python/cpython/pull/100624

Based off cpython commit c4c5790120beabed83ce5855f18d209ab8324434

Installation

Requires a sufficiently recent Python 3.12 version (some tests fail with earlier 3.12 versions, although the main functionality might still work - do your own testing).

pip3 install singledispatch-with-type-arg-support

Example

See example.py:

from singledispatch_with_type_arg_support import singledispatch

@singledispatch
def describe(x) -> str:
  raise TypeError(f"no description for {repr(x)}")

@describe.register
def _(x: type[int]) -> str:
  return "the integer type"

print(describe(int))  # should print: the integer type

License

Same as CPython (as 99% of it is copied from there), see LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page