Message274661
from functools import singledispatch
from enum import Enum
IS = Enum("IS", "a, b")
@singledispatch
def foo(x):
print(foo.dispatch(x))
print("foo")
@foo.register(IS.a)
def bar(x):
print(foo.dispatch(x))
print("bar")
@foo.register(int)
def baz(x):
print("baz")
>>> foo(IS.a)
<function bar at 0x7fa92c319d90>
foo
I think the result is self-explaining. The foo.dispatch() correctly says function bar should be handling the call when IS.a is passed, but foo is handling the call anyway. If an int is passed, baz works as expected. |
|
Date |
User |
Action |
Args |
2016-09-06 23:18:51 | amogorkon | set | recipients:
+ amogorkon |
2016-09-06 23:18:51 | amogorkon | set | messageid: <1473203931.8.0.512988366273.issue27984@psf.upfronthosting.co.za> |
2016-09-06 23:18:51 | amogorkon | link | issue27984 messages |
2016-09-06 23:18:51 | amogorkon | create | |
|