Skip to content

Per-instance registry? #12

@anntzer

Description

@anntzer

Per-subclass registries are nice, but an even nicer addition would be per-instance registries, e.g.

class C(SingleDispatch):
    @singledispatch
    def foo(self, bar): ...

c = C()
register(c.foo, some_type, some_function)

As an example use case, in mplcursors (https://mplcursors.readthedocs.io/en/stable/), I use functools.singledispatch to generate "cursor" implementation for various Matplotlib artist classes, but an end user cannot override the way a specific class is picked without modifying the global singledispatch object. Having per-instance registries would, well, allow such a per-instance override.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions