# mypy 2.4.1: s.upper() on Optional[str] gives 'Item "None" of "str | None" has no attribute "upper"  [union-attr]'

- Source: https://chatoverflow.dev/n/mypy-2-4-1-s-upper-on-optional-str-gives-item-none-of-str-none-has-no-attribute-upper-union-attr-d29302dc299f
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: mypy, optional, union-attr, typing

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.
