-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
stubs: false positiveType checkers report false errorsType checkers report false errors
Description
Bug Report
Starting in 1.4 (and also reproduced in 1.5 and on master) configparser.SectionProxy.get doesn't honor the fallback TypeVar in the overloaded signature.
To Reproduce
from configparser import SectionProxy
sp: SectionProxy
num: str = sp.get('foo', fallback="hi") # errors because mypy thinks this can return None
reveal_type(sp.get) # TypeVars improperly bound "fallback: _T`345"https://mypy-play.net/?mypy=latest&python=3.11&gist=803668872116798ed5e0c478bcb827c5
Expected Behavior
main.py:6: note: Revealed type is "def (option: builtins.str, fallback: Union[builtins.str, None] =, *, raw: builtins.bool =, vars: Union[typing.Mapping[builtins.str, builtins.str], None] =, _impl: Union[Any, None] =, **kwargs: Any) -> Union[builtins.str, Any]"
Success: no issues found in 1 source file
Actual Behavior
main.py:5: error: Incompatible types in assignment (expression has type "str | None", variable has type "str") [assignment]
main.py:6: note: Revealed type is "Overload(
def (option: builtins.str, *, raw: builtins.bool =, vars: Union[typing.Mapping[builtins.str, builtins.str], None] =, _impl: Union[Any, None] =, **kwargs: Any) -> Union[builtins.str, None],
def [_T] (option: builtins.str, fallback: _T`345, *, raw: builtins.bool =, vars: Union[typing.Mapping[builtins.str, builtins.str], None] =, _impl: Union[Any, None] =, **kwargs: Any) -> Union[builtins.str, _T`345])"
Found 1 error in 1 file (checked 1 source file)
Your Environment
Stubs for this method is here:
https://github.com/python/mypy/blob/e93f06ceab81d8ff1f777c7587d04c339cfd5a16/mypy/typeshed/stdlib/configparser.pyi#L306-L320
- Mypy version used: 1.4, 1.5
- Python version used: 3.11
Metadata
Metadata
Assignees
Labels
stubs: false positiveType checkers report false errorsType checkers report false errors