Skip to content

Remove/improve some more casts to Any #14828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2023

Conversation

AlexWaygood
Copy link
Member

No description provided.

@github-actions

This comment has been minimized.

@@ -55,13 +55,13 @@ def record_literal(self, value: LiteralValue) -> None:
tuple_literals = self.tuple_literals
if value not in tuple_literals:
for item in value:
self.record_literal(cast(Any, item))
self.record_literal(cast(LiteralValue, item))
Copy link
Member

Choose a reason for hiding this comment

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

Not familiar with this code, but I wonder whether this can be an assert instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I'll try it.

Copy link
Member Author

@AlexWaygood AlexWaygood Mar 3, 2023

Choose a reason for hiding this comment

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

LiteralValue is a union, so I had to use a TypeGuard in order to convert this code to using assert:

# Supported Python literal types. All tuple / frozenset items must have supported
# literal types as well, but we can't represent the type precisely.
LiteralValue = Union[
str, bytes, int, bool, float, complex, Tuple[object, ...], FrozenSet[object], None
]

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

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

mypyc literals.py changes look good 👍

@JelleZijlstra JelleZijlstra merged commit c91849d into python:master Mar 4, 2023
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