Skip to main content

A small library to provide multi-methods. All functions are in the dialogue.multi_method package.

To create a multi-method, create a dispatch function, that takes the arguments and returns a hashable value, that is used to dispatch on. Use the @multi function annotation to annotate the function.

For each value of the dispatch function that you want to be handled differently, create a method with that dispatch value.

You can define a method with no dispatch value, that becomes the default method if no other method is defined for a dispatch value.

An example:

@multi
def number(x):
  return x


@method(number, 1)
def number_one(x):
  return 'one'


@method(number)
def number_other(x):
  return "not one, but "+ str(c)


assert number(1) == 'one'
assert number(0) == 'not one, but 0'

The dispatch function is available, e.g. for testing:

assert dispatch_fn(number)('x') == 'x'

Release files for dialogue.multi-method 0.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 dialogue.multi-method 0.0.5
File Size Uploaded
dialogue.multi-method-0.0.5.tar.gz 2.5 kB Details

Release files / dialogue.multi-method-0.0.5.tar.gz

Download URL dialogue.multi-method-0.0.5.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6f83adb2802c327514d1ad3fdb32cfefcc0818ba1e6281a35b595254caa21473
BLAKE2b-256 checksum
How to use checksums
8d591dc742320c5dc21abac38553deb11b34482e2c7779dbb30ab05dc5de8167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.9.1 pkginfo/1.4.1 requests/2.18.3 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/3.6.1

Release history Release notifications | RSS feed

This release

0.0.5 This release

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

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