The following code:
from typing import *
A = TypeVar('A')
class Foo(Generic[A]):
pass
issubclass((Foo,), Foo)
fails with:
TypeError: cannot create weak reference to 'tuple' object
I think this is a bug.
The only bug here is the strange error message. Both issubclass(1, int) and issubclass([], collections.abc.Iterable) fail with TypeError (the error message in the second case is also weird). The reason I think is that ABCMeta tries to add (Foo,) to the negative cache, which is implemented as a WeakSet.
I mean, the bug is the error, no? It is coming from caching, not from type check itself. Maybe negative cache should be implemented so that if weak ref cannot be set, then cache is not used, but not that it explodes.
To be clear, issubclass(x, Y) where x is not a class is always an error in the source code. The bug here is that you get a weird error rather than the regular TypeError: issubclass() arg 1 must be a class. But your code is wrong in either case (and it's still a TypeError).
Oh, of course. I somehow missed that here (code was just automatically checking things).
I just checked on Python 3.8 the error is much better: TypeError: issubclass() arg 1 must be a class. So I think this can be closed now.
Most helpful comment
To be clear,
issubclass(x, Y)wherexis not a class is always an error in the source code. The bug here is that you get a weird error rather than the regularTypeError: issubclass() arg 1 must be a class. But your code is wrong in either case (and it's still aTypeError).