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
The presence of issubclass(...) in the code sample that follows causes arg to take on type Union[T, Type[object]]. This change in type leads to false positives, as demonstrated below.
fromtypingimportTypeVarT=TypeVar('T')
deffunction(arg: T) ->T:
ifisinstance(arg, type) andissubclass(arg, Exception):
raiseRuntimeErrorreturnarg# error: Incompatible return value type (got "Union[T, Type[object]]", expected "T") [return-value]
Expected Behavior
No errors should be reported. Testing the type of a variable should not change the type of the variable as seen outside the controlled code blocks (if/else).
Actual Behavior
The type of arg is changed, leading to a false positive as noted in the code sample above.
Your Environment
Mypy version used: 0.910 [edit: verified with 1.9.0]
Mypy command-line flags: (none necessary)
Mypy configuration options from mypy.ini (and other config files): (none)
Python version used: 3.8.3 from pyenv [edit: verified with 3.10]
Operating system and version: macOS 10.14 with homebrew
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
The presence of
issubclass(...)
in the code sample that follows causesarg
to take on typeUnion[T, Type[object]]
. This change in type leads to false positives, as demonstrated below.To Reproduce
Run mypy on the following code: mypy-play.net
Expected Behavior
No errors should be reported. Testing the type of a variable should not change the type of the variable as seen outside the controlled code blocks (if/else).
Actual Behavior
The type of
arg
is changed, leading to a false positive as noted in the code sample above.Your Environment
mypy.ini
(and other config files): (none)The text was updated successfully, but these errors were encountered: