Skip to main content
https://img.shields.io/pypi/v/multimethod.svg https://img.shields.io/pypi/pyversions/multimethod.svg https://img.shields.io/pypi/status/multimethod.svg https://img.shields.io/travis/coady/multimethod.svg https://img.shields.io/codecov/c/github/coady/multimethod.svg

Call multimethod on a variable number of types. It returns a decorator which finds the multimethod of the same name, creating it if necessary, and adds that function to it.

@multimethod(*types)
def func(*args):
   pass

func is now a multimethod which will delegate to the above function, when called with arguments of the specified types. If an exact match can’t be found, the next closest method is called (and cached).

If strict mode is enabled, and there are multiple candidate methods, a TypeError is raised. A function can have more than one multimethod decorator. Keyword arguments can be used when calling, but won’t affect the dispatching.

The functools.singledispatch style syntax introduced in Python 3.4 is also supported.

@multidispatch
def func(*args):
   pass

@func.register(*types)
def _(*args):
   pass

See tests for more example usage.

Installation

$ pip install multimethod

Dependencies

Python 2.7 or 3.3+.

Tests

100% branch coverage.

$ py.test [--cov]

Changes

0.5

  • Optimized dispatching

  • Support for functools.singledispatch syntax

0.4

  • Dispatch on Python 3 annotations

Metadata

Release files for multimethod 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multimethod 0.5
File Size Uploaded
multimethod-0.5.tar.gz 4.3 kB Details

Release files / multimethod-0.5.tar.gz

Download URL multimethod-0.5.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2ddba71265cb51dfd3d078b86b2bf57d47426ccf810bd2a695dfcce75526083d
BLAKE2b-256 checksum
How to use checksums
c13c65ea1ca4f580ec9224c4d0c85cba9b0b440971e2aea147cbbb1c8115681d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.1

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0

2 release files

1.12

2 release files

1.11.2

2 release files

1.11.1

2 release files

1.11

2 release files

1.10

2 release files

1.9.1

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

0.7.1

2 release files

0.7

2 release files

0.6

2 release files

This release

0.5 This release

1 release file

0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page