| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Diff from mypy_primer, showing the effect of this PR on open source code: zulip (https://github.com/zulip/zulip)
- zerver/lib/validator.py:331: error: Redundant cast to "ResultT" [redundant-cast]
|
Sorry, something went wrong.
Not just the LHS but the RHS too? See sample reproduction in #21199 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
When a variable is compared with == against a TypeVar operand, mypy was narrowing the left-hand variable to the TypeVar type. This caused false errors on subsequent operations — for example, x: int would be narrowed to T after assert x == y (where y: T), causing x += 1 to be flagged as unsupported operands.
The regression was introduced in #20602, which routed == through narrow_type_by_identity_equality but did not guard against TypeVar targets. A TypeVar represents an unknown concrete type at the call site, so narrowing based on it can only lose information, not gain it.
This fix skips narrowing in narrow_type_by_identity_equality when the target type is a TypeVarLikeType. A more precise approach — intersecting the expression type with the TypeVar's upper bound — would require intersection type support and can be done as a follow-up.
Fixes #21199