-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Disambiguate between str and enum member args to typing.Literal #7414
Conversation
Pull Request Test Coverage Report for Build 3027673818
💛 - Coveralls |
This comment has been minimized.
This comment has been minimized.
tests/functional/u/unused/unused_name_in_string_literal_type_annotation.py
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
tests/functional/u/unused/unused_name_in_string_literal_type_annotation.py
Show resolved
Hide resolved
tests/functional/u/unused/unused_name_in_string_literal_type_annotation_py38.py
Outdated
Show resolved
Hide resolved
pylint/checkers/variables.py
Outdated
@@ -2940,7 +2930,19 @@ def visit_const(self, node: nodes.Const) -> None: | |||
if origin is not None and utils.is_typing_literal(origin): | |||
return | |||
|
|||
self._type_annotation_names.append(node.value) | |||
if node.value.isidentifier(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why you moved this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the is_typing_literal part up to stop checking for names if the string node is an arg to Literal
. As for the isidentifier
check, it's probably not needed anymore. I'll push some more changes.
…nnotation_py38.py Co-authored-by: Daniël van Noord <[email protected]>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does need a news fragment still.
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 24fc87f |
Thanks you @lggruspe! |
@Pierre-Sassoulas Should this be included as well? Milestone is missing (my bad probably) but it has the label. |
Let's add it too. |
…nt-dev#7414) Co-authored-by: Daniël van Noord <[email protected]>
…nt-dev#7414) Co-authored-by: Daniël van Noord <[email protected]>
Co-authored-by: Daniël van Noord <[email protected]>
Type of Changes
Description
This is a continuation of #7400. This PR fixes some errors in the handling of typing.Literal.
From https://peps.python.org/pep-0586/#literals-enums-and-forward-references: