Open
Description
Bug Report
The default values for function parameters are evaluated during definition, and late-bound defaults aren't a thing yet, so type narrowing should work for them just fine.
To Reproduce
# demo.py
from typing import Optional
foo: Optional[int] = 42
assert foo is not None
reveal_type(foo) # demo.py:5: note: Revealed type is "builtins.int"
def bar(arg: int = foo) -> None: # demo.py:7: error: Incompatible default for argument "arg" (default has type "Optional[int]", argument has type "int")
...
Expected Behavior
There should be no error.
Actual Behavior
demo.py:7: error: Incompatible default for argument "arg" (default has type "Optional[int]", argument has type "int")
Your Environment
- Mypy version used: 0.961 (compiled: yes)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): N/A - Python version used: 3.10.1
- Operating system and version: Ubuntu 20.04