Use information from @overload
to better model narrowing in implementation
#14666
Labels
@overload
to better model narrowing in implementation
#14666
Bug Report
There are potentially two issues that I have encountered:
@overload
and, for example, two arguments have narrower types than the signature of the non-@overload
-decorated definition. If one of those is aLiteral
type and we branch on a comparison to the value of that literal type, the other argument isn't narrowed to the type(s) defined in the matching overloaded function(s).isinstance()
, but it seems redundant.isinstance()
is checked on the other argument, it's not possible to narrow, but it should be after.isinstance()
to narrow the type of a value, a subsequent nested function definition keeps the non-narrowed type when referring to the value.See the reproducer below which should help clarify the above issues.
To Reproduce
See playground example.
Expected Behavior
Something like this mocked up output if the the type of
value
were narrowed based on the literal ofname
:Something like this mocked up output if only the type inside the nested function respected the narrowing performed by the
isinstance()
calls:Actual Behavior
Your Environment
1.0.0
--strict
mypy.ini
(and other config files): N/A3.10.9
The text was updated successfully, but these errors were encountered: