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
Python 3.5, but I'm using typing.py from this repo, master branch. (Trying to port a library.)
I realize this is not really the intended use of typing.
I'm not really sure if this is an issue in typing or singledispatch, but it used to work before. Here's a small test case. Note that typing.Tuple[int] is a subclass of typing.Tuple, and typing.Tuple is a subclass of typing.Sequence.
import typing
from functools import singledispatch
s = singledispatch(lambda: 'default')
s.register(typing.Sequence, lambda: 'sequence')
s.register(typing.Tuple, lambda: 'tuple')
print(s.dispatch(typing.Tuple[int])())
If you run it a number of times, the results are either 'tuple' or 'sequence', based on the ordering of an internal dict in singledispatch. This is a bug in singledispatch, right?
The text was updated successfully, but these errors were encountered:
This looks indeed like a subtle bug in singledispatch, it should raise an error in ambiguous situations.
However, while playing with this, I have found another issue: issubclass(Node[int], Node) returns False. I would like it to return True and I have a very simple fix that accidentally also fixes your case to always print 'tuple' (which is right, since it is a more narrow type, and singledispatch determines this correctly).
Hello,
Python 3.5, but I'm using
typing.py
from this repo, master branch. (Trying to port a library.)I realize this is not really the intended use of typing.
I'm not really sure if this is an issue in
typing
orsingledispatch
, but it used to work before. Here's a small test case. Note thattyping.Tuple[int]
is a subclass oftyping.Tuple
, andtyping.Tuple
is a subclass oftyping.Sequence
.If you run it a number of times, the results are either 'tuple' or 'sequence', based on the ordering of an internal dict in singledispatch. This is a bug in singledispatch, right?
The text was updated successfully, but these errors were encountered: