Closed as not planned
Closed as not planned
Description
Bug Report
In this code, mypy --strict is unhappy both with and without a cast (playground):
from typing import cast
def foo(name: str) -> None:
pass
def bar(
name: str | None = None,
) -> None:
if name is None:
name = "foo"
a = [lambda: foo(name)] # incompatible type "str | None"; expected "str"
b = [lambda: foo(cast(str, name))] # Redundant cast to "str"
del a, b
Expected Behavior
One of the lines should be ok for mypy.
Actual Behavior
main.py:14: error: Argument 1 to "foo" has incompatible type "str | None"; expected "str" [arg-type]
main.py:15: error: Redundant cast to "str" [redundant-cast]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.6.1, master
- Mypy command-line flags: --strict
- Python version used: 3.11, 3.12