seequent / methoddispatch Goto Github PK
View Code? Open in Web Editor NEWpython singledispatch implementation for methods
License: BSD 3-Clause "New" or "Revised" License
python singledispatch implementation for methods
License: BSD 3-Clause "New" or "Revised" License
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.
This is because the name is mangled in the attributes dictionary, but not elsewhere.
your setup.py says "BSD", please include a license file with actual license text.
Python 3.7 has added an support for reading the override type from the function annotation.
We should support this too on python 3.7.
You can't navigate from a string to the method you are dispatching.
permit:
class SubClass(BaseClass):
@register(BaseClass.foo, int)
def foo_int(self, bar):
...
a singledispatch decorated function has public registry and dispatch attributes. These are not present on the bound and unbound methods returned by Class.foo or instance.foo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.