Message326965
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. |
|
| Date |
User |
Action |
Args |
| 2018-10-03 11:54:35 | techdragon | set | recipients:
+ techdragon, gvanrossum, rhettinger, lukasz.langa, levkivskyi, Dutcho, enedil |
| 2018-10-03 11:54:35 | techdragon | set | messageid: <[email protected]> |
| 2018-10-03 11:54:35 | techdragon | link | issue34498 messages |
| 2018-10-03 11:54:34 | techdragon | create | |
|