This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author techdragon
Recipients Dutcho, enedil, gvanrossum, levkivskyi, lukasz.langa, rhettinger, techdragon
Date 2018-10-03.11:54:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
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.
History
Date User Action Args
2018-10-03 11:54:35techdragonsetrecipients: + techdragon, gvanrossum, rhettinger, lukasz.langa, levkivskyi, Dutcho, enedil
2018-10-03 11:54:35techdragonsetmessageid: <[email protected]>
2018-10-03 11:54:35techdragonlinkissue34498 messages
2018-10-03 11:54:34techdragoncreate