Related Bug
Could be a duplicate of:
Bug Report
When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is raised
To Reproduce
Run mypy against the following file:
fromtypingimportOptionalanimals= ["cow"]
deffind1(name: str) ->Optional[str]:
returnnext(
filter(
lambdaanimal: animal.upper() ==name,
animals,
),
None,
)
Expected Behavior
No type errors should be returned
Actual Behavior
$ mypy bug.py
bug.py:9: error: Item "None" of "Optional[str]" has no attribute "upper"
NOTE: Same error with returning "Union[str, None]"
NOTE: Removing the Optional[str] stops the error, but that defaults the point
deffind1(name: str):
returnnext(
filter(
lambdaanimal: animal.upper() ==name,
animals,
),
None,
)
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini (and other config files): None - Python version used: 3.9.4
- Operating system and version: MacOS 10.15.7
Related Bug
Could be a duplicate of:
Bug Report
When running mypy with a function returning an Optional the contains of a lambda expression is interpreted as optional and a type error is raised
To Reproduce
Run
mypyagainst the following file:Expected Behavior
No type errors should be returned
Actual Behavior
NOTE: Same error with returning "Union[str, None]"
NOTE: Removing the Optional[str] stops the error, but that defaults the point
Your Environment
mypy.ini(and other config files): None