Bug with `match.group().count` in loop on v1.15.0
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
On v1.15.0, with mypy --warn-unreachable ... successfully finds no errors with
import re
re.sub("x", lambda m: m.group().count("x") * "x", "x")
but reports an error with
import re
for _ in re.findall("x", "x"):
re.sub("x", lambda m: m.group().count("x") * "x", "x") # E: Argument 1 to "count" of "bytes" has incompatible type "str"; expected "Buffer | SupportsIndex" [arg-type]
for reference, both examples pass with v1.14.1 and with v1.15.0 without --warn-unreachable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two provided Python snippets with mypy 1.15.0 and 1.14.1, comparing behavior with and without --warn-unreachable. Trace the handling of re.Match.group().count inside the unreachable-code analysis, then add regression coverage showing that the loop example does not report an incompatible str argument.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100