Uh oh!
There was an error while loading. Please reload this page.
Use a single pass for core narrowing logic, add comments - #20659
Conversation
for more information, see https://pre-commit.ci
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
hauntsaninja
commented
Jan 28, 2026
Merging, but comments are very welcome! |
Uh oh!
There was an error while loading. Please reload this page.
cdce8p
commented
Jan 28, 2026
This change seems to have introduced a small regression. fromenumimportStrEnumclassCapability(StrEnum):
COLOR_CONTROL="colorControl"COLOR_TEMPERATURE="colorTemperature"deffunc(capability: Capability|str):
ifcapabilityin (Capability.COLOR_CONTROL, Capability.COLOR_TEMPERATURE):
reveal_type(capability)# beforeCapability# nowCapability|strIt reverses part of the improvement from #20602. |
hauntsaninja
commented
Jan 28, 2026
Thanks for the post, but this is actually an improvement! I have tests for this fix in my stack, but it looks like I split the tests for this change into a different commit Ideally we could narrow to a literal, but in general mypy is missing a bunch of logic around the values of enums |
hauntsaninja
commented
Jan 28, 2026
#20672 includes more tests here |
cdce8p
commented
Jan 28, 2026
Good point, missed that! Thanks for working on it. |
This PR should not change semantics
We refactor to avoid the separate loops for
type_targetsandvalue_targets, which allows the logic to be more consolidated, helps with future changes and is probably faster