Closed
Description
With a cast()
in a lambda, --warn-redundant-cast
tells me to remove the cast, but then I get a different error if I actually do so. This is a regression in 0.790.
$ cat tmp/matchcast.py
from typing import cast, Match, Pattern
def _get_nodes(key: str, rgx: Pattern[str]) -> None:
matches = rgx.fullmatch(key)
if matches is None:
return
sorted(
matches.groupdict().items(),
key=lambda g: cast(Match[str], matches).start(g[0]),
)
$ mypy --warn-redundant-casts tmp/matchcast.py
tmp/matchcast.py:11: error: Redundant cast to "Match[str]"
Found 1 error in 1 file (checked 1 source file)
And if I remove the cast:
$ mypy --warn-redundant-casts tmp/matchcast.py
tmp/matchcast.py:11: error: Item "None" of "Optional[Match[str]]" has no attribute "start"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags:
--warn-redundant-casts
- Python version used: 3.6
- Operating system and version: Ubuntu