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
Mypy is evaluating builtins.object instead of Union[X, Y] as the returned type when passing an argument of type Type[Union[X, Y]] to a def [T] (cl: Type[T']) -> T' function.
scratch.py:11: note: Revealed type is "Type[builtins.int]"
scratch.py:12: note: Revealed type is "def [T] (cl: Type[T`-1]) -> T`-1"
scratch.py:14: note: Revealed type is "builtins.int"
Success: no issues found in 1 source file
Using str instead of int above also works as expected the same way.
scratch.py:11: note: Revealed type is "Union[Type[builtins.int], Type[builtins.str]]"
scratch.py:12: note: Revealed type is "def [T] (cl: Type[T`-1]) -> T`-1"
scratch.py:14: note: Revealed type is "Union[builtins.int, builtins.str]"
Success: no issues found in 1 source file
or
scratch.py:11: note: Revealed type is "Type[Union[builtins.int, builtins.str]]"
scratch.py:12: note: Revealed type is "def [T] (cl: Type[T`-1]) -> T`-1"
scratch.py:14: note: Revealed type is "Union[builtins.int, builtins.str]"
Success: no issues found in 1 source file
(Type[Union[X, Y]] instead of Union[Type[X], Type[Y]] in line 11)
Actual Behavior
Output:
scratch.py:11: note: Revealed type is "Union[Type[builtins.int], Type[builtins.str]]"
scratch.py:12: note: Revealed type is "def [T] (cl: Type[T`-1]) -> T`-1"
scratch.py:14: note: Revealed type is "builtins.object"
scratch.py:15: error: Incompatible return value type (got "object", expected "int | str") [return-value]
Found 1 error in 1 file (checked 1 source file)
(revealed type in line 14 is "builtins.object" instead of "Union[builtins.int, builtins.str]")
The error looks like might be because of the covariance of Union.
Your Environment
Mypy version used: 1.4.1
Mypy command-line flags: just the file name, no extra flags.
Mypy configuration options from mypy.ini (and other config files):
Bug Report
Mypy is evaluating
builtins.object
instead ofUnion[X, Y]
as the returned type when passing an argument of typeType[Union[X, Y]]
to adef [T] (cl: Type[T']) -> T'
function.To Reproduce
This works as expected:
Output:
Using
str
instead ofint
above also works as expected the same way.But this does not:
Expected Behavior
Output:
or
(
Type[Union[X, Y]]
instead ofUnion[Type[X], Type[Y]]
in line 11)Actual Behavior
Output:
(revealed type in line 14 is
"builtins.object"
instead of"Union[builtins.int, builtins.str]"
)The error looks like might be because of the covariance of
Union
.Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: