Skip to content

Conversation

@randolf-scholz
Copy link
Contributor

@randolf-scholz randolf-scholz commented Dec 20, 2025

Fixes #20445

Fixes a regression in conditional_type when given a union of Any | Protocol

proposed_type = make_simplified_union(proposed_items)

if isinstance(proper_type, AnyType):
return proposed_type, current_type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, would it be technically more correct to return AnyType(TypeOfAny.from_another_any, source_any=proper_type) for the else branch, rather than proper_type itself?

return default, UninhabitedType()
elif not is_overlapping_types(current_type, proposed_type, ignore_promotions=True):
return default, remainder
if not is_overlapping_types(current_type, proposed_type, ignore_promotions=True):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the elif to if because the if not any(type_range.is_upper_bound for type_range in proposed_type_ranges): is not guaranteed to return anymore.

)
):
# Expression is always of one of the types in proposed_type_ranges
return default, UninhabitedType()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return was problematic in the structural case when current_type=Any | Proto, restricting Proto away should leave us with Any and not Never.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1.19 regression] Ternary expression involving a union with Any evaluated as redundant

1 participant