Bug Report
Consider the following snippet. (This is a minified example of the problem detected in matrix-org/synapse#12996.)
import re
"#" + re.sub(
"PATTERN",
lambda match: match.group(0) + "ANOTHER_STRING",
"HAYSTACK",
)
Mypy 0.950 is happy with this, but mypy 0.960 is not.
main.py:5: error: Unsupported operand types for + ("bytes" and "str")
AFAICS this is a legitimate usage of re.sub, consistent with the stubs defined in typeshed.
Additional
Strangely, removing either of the addition operators and the corresponding string literal causes mypy 0.960 to accept the snippet. That is, applying this change
- "#" + re.sub(
+ re.sub(
is accepted, and applying this change
- lambda match: match.group(0) + "ANOTHER_STRING",
+ lambda match: match.group(0),
to the vanilla snippet above is also accepted.
I'm not sure how to get mypy to reveal the type of an expression in a lambda body, but I'd guess that in the error cases it deduces match: Match[bytes] rather than match: Match[str]?
Bug Report
Consider the following snippet. (This is a minified example of the problem detected in matrix-org/synapse#12996.)
Mypy 0.950 is happy with this, but mypy 0.960 is not.
AFAICS this is a legitimate usage of re.sub, consistent with the stubs defined in typeshed.
Additional
Strangely, removing either of the addition operators and the corresponding string literal causes mypy 0.960 to accept the snippet. That is, applying this change
is accepted, and applying this change
to the vanilla snippet above is also accepted.
I'm not sure how to get mypy to reveal the type of an expression in a lambda body, but I'd guess that in the error cases it deduces
match: Match[bytes]rather thanmatch: Match[str]?