-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Mypy incorrectly reports two errors in this (python 2) snippet.
$ nl -ba /tmp/foo.py
1 import typing
2
3 def foo(value):
4 # type: (typing.Union[unicode, bytes]) -> None
5 if isinstance(value, unicode):
6 return
7 if not isinstance(value, bytes):
8 raise TypeError("Expected bytes or unicode; got %r" % type(value))
$ PYTHONPATH=. scripts/mypy --py2 /tmp/foo.py
/tmp/foo.py: note: In function "foo":
/tmp/foo.py:7: error: Argument 1 to "isinstance" has incompatible type "Union[object, object]"; expected "object"
/tmp/foo.py:8: error: No overload variant of "type" matches argument types [Union[<ERROR>, <ERROR>, <ERROR>, <ERROR>]]
If lines 5 and 6 are removed, the errors disappear. If line 7 is replaced with if True:, the error on line 8 remains. Replacing unicode with str and running mypy in py3 mode also makes the errors disappear.
Kukuster
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong