Sam Bishop <s...@psyx.co> added the comment:
Would the enhancements to resolve this, by making singledispatch accept more things, also resolve the AssertionError from functools.singledispatch when passing it custom types, or should I raise this as a separate issue? ------------------------------------------------ from typing import NewType, List from functools import singledispatch @singledispatch def fun(arg, verbose=False): if verbose: print("Let me just say,", end=" ") print(arg) MyType = NewType('MyType', List[int]) @fun.register def _(arg: MyType , verbose=False): if verbose: print("Strength in numbers, eh?", end=" ") print(arg) --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-49-e549104faa9a> in <module> 5 6 @fun.register ----> 7 def _(arg: MyType , verbose=False): 8 if verbose: 9 print("Strength in numbers, eh?", end=" ") ~/.pyenv/versions/3.7.0/lib/python3.7/functools.py in register(cls, func) 809 argname, cls = next(iter(get_type_hints(func).items())) 810 assert isinstance(cls, type), ( --> 811 f"Invalid annotation for {argname!r}. {cls!r} is not a class." 812 ) 813 registry[cls] = func AssertionError: Invalid annotation for 'arg'. <function NewType.<locals>.new_type at 0x10fcd7730> is not a class. ---------- nosy: +techdragon _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34498> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com