Skip to content

Conversation

@missingdays
Copy link
Contributor

This pull request marks optional type narrowing in tuples_type_compat.py with E? to signify its optionality. Otherwise, it is treated as obligatory.

See the comment NOTE: This type narrowing functionality is optional, not mandated. at the beginning of each function.

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 22, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@erictraut
Copy link
Collaborator

I agree these should be marked with "E?" rather than "E" because they are optional in the spec. Thanks for the fix.

@erictraut erictraut merged commit c55a4d0 into python:main Apr 22, 2025
4 checks passed
if len(val) == 1:
# Type can be narrowed to tuple[int].
assert_type(val, tuple[int]) # tuple[int]
assert_type(val, tuple[int]) # E?: tuple[int]
Copy link
Member

Choose a reason for hiding this comment

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

This makes the test not very useful (without manual review) since type checkers will now pass no matter what type they infer for val. One solution could be to use two types and asserts that exactly one of them errors, by using an error group and asserting for both the narrowed and non-narrowed type. However, we don't currently check in that case that there is exactly one error. I can send a PR doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable to me.

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.

3 participants