[New-bugs-announce] [issue27984] singledispatch is wonky with enums

Anselm Kiefner report at bugs.python.org
Tue Sep 6 19:18:51 EDT 2016


New submission from Anselm Kiefner:

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.

----------
messages: 274661
nosy: amogorkon
priority: normal
severity: normal
status: open
title: singledispatch is wonky with enums
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27984>
_______________________________________


More information about the New-bugs-announce mailing list