Skip to main content

Container Dispatch

why?

Because this code doesnt work natively:

@dispatch.register
def _(arg: list[int|str]):
    return "this is a list of ints and strings!"

the stdlib functools.singledispatch returns:

TypeError: Invalid annotation for 'arg'. list[int|str] is not a class.

This means we have to simplify the annotation at the expense of complicating the function, and less support for mypy:

@dispatch.register
def _(arg: list):
    # list[int|str]
    if all(isinstance(i, (int,str)) for i in arg):
        return "this is a list of ints and strings!"

    # elif <other types>:
        # other logic

    else:
        # list[any]

Personally I find this antitheitcal to singledispatch, which is supposed to solve this exact problem! The entire reason I reached for singledispatch was to replace these if-ridden router functions, and I refused to accept this.

Metadata

Release files for containerdispatch 0.1.2

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

Source distribution (sdist)

Source distribution for containerdispatch 0.1.2
File Size Uploaded
containerdispatch-0.1.2.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for containerdispatch 0.1.2
File Interpreter ABI Platform
containerdispatch-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / containerdispatch-0.1.2.tar.gz

Download URL containerdispatch-0.1.2.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9410e2d706cb674262212b43137de5e5364470bcd2381f9319cd9c9ea8b18739
BLAKE2b-256 checksum
How to use checksums
d5997e47ad21835c5c3b7d30dc09bbee68cece50ec478f646209a59e7fa6920b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release files / containerdispatch-0.1.2-py3-none-any.whl

Download URL containerdispatch-0.1.2-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
276da8812da1cdd118944cb5167aa0a20b11d947494d4deea1f19a46575c1ae0
BLAKE2b-256 checksum
How to use checksums
92a0e8fd05827f65500460abe00632c6f40f6563f847858373a13ea589e8e244
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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