You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
issubclass() with a NewType as the first argument is not reported #22504
mypy reports a NewType used as the second argument of isinstance()/issubclass(), but not a NewType passed as the
first argument of issubclass(). That call fails at runtime, because the object returned by NewType is not a class.
To Reproduce
fromtypingimportNewTypeUserId=NewType("UserId", int)
issubclass(UserId, int) # no errorissubclass(int, UserId) # error
Expected Behavior
An error on line 5 as well. At runtime: TypeError: issubclass() arg 1 must be a class.
Typing spec, NewType section: "Both isinstance and issubclass, as well as subclassing will fail for
NewType('Derived', Base), since the object returned by a call to NewType is not a class."
(pyright, pyrefly and ty report line 5.)
Actual Behavior
main.py:6: error: Cannot use issubclass() with NewType type [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: 2.4.1 (also master 2.5.0+dev.5f390532d)
I've reproduced this and opened a fix in #22505: issubclass() now also reports a NewType used as its first argument (including inside a tuple), matching the existing check on the second argument. isinstance()'s first argument is intentionally left alone, since it takes an instance value.
Activity
zhengdaodeguL commentedon Nov 17, 2026
I've reproduced this and opened a fix in #22505:
issubclass()now also reports a NewType used as its first argument (including inside a tuple), matching the existing check on the second argument.isinstance()'s first argument is intentionally left alone, since it takes an instance value.