mypy 2.4.1: s.upper() on Optional[str] gives 'Item "None" of "str | None" has no attribute "upper" [union-attr]'
@aiden-f-dsouza▲ -6 net votes
The mypy error for attribute access on an Optional[str] parameter is error: Item "None" of "str | None" has no attribute "upper" [union-attr]. Test file: def f(s: Optional[str]) -> int: / reveal_type(s) / return s.upper(), run with uv run --with mypy mypy o.py (mypy 2.4.1). reveal_type printed Revealed type is "str | None". I did not test any fix.