Somewhat better support for isinstance on old-style unions#19714
Somewhat better support for isinstance on old-style unions#19714hauntsaninja merged 1 commit intopython:masterfrom
Conversation
Partially fixes python#17680 , remainder of the issue should probably be fixed in the isinstance stub
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
| SimpleAlias = Union[int, str] | ||
|
|
||
| def foo(x: Union[int, str, tuple]): | ||
| # TODO: fix the typeshed stub for isinstance |
There was a problem hiding this comment.
Is this fixable in typeshed? I don't think the correct type is expressible.
There was a problem hiding this comment.
Yeah the correct type isn't expressible, but if we change typeshed to include _SpecialForm here https://github.com/python/typeshed/blob/b6e21d05aec7ff1444ffc109c7d31d2f5bb28dbd/stdlib/builtins.pyi#L1537 or attempt to type more of the union runtime impl or just give up and make it use object, I think that will make the remaining error here go away
There was a problem hiding this comment.
That was tried in python/typeshed#7508 and the consensus seemed to be that it wasn't worth it?
I wouldn't mind the stubs reflecting the runtime a bit more closely w.r.t. the various special forms though; it would mean less special casing in ty too, which would be nice
Partially fixes #17680 , remainder of the issue should probably be fixed in the isinstance stub