-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
False negative - tuple unpacking #5708
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
False negative - tuple unpacking #5708
Conversation
Pull Request Test Coverage Report for Build 1769225036
π - Coveralls |
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.
Small question(s) π
for more information, see https://pre-commit.ci
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.
Thank you, this looks great already ! I suggested some more tests cases, let me know what you think @mbyrnepr2
Co-authored-by: Pierre Sassoulas <[email protected]>
Co-authored-by: Pierre Sassoulas <[email protected]>
for more information, see https://pre-commit.ci
pylint/checkers/variables.py
Outdated
@@ -2430,6 +2423,17 @@ def _check_unpacking(self, inferred, node, targets): | |||
args=(_get_unpacking_extra_info(node, inferred),), | |||
) | |||
|
|||
@staticmethod | |||
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List]: |
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 add typing to the List? I guess:
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List]: | |
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List[nodes.AssignName]]: |
Or:
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List]: | |
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List[nodes.NodeNG]]: |
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.
Good point; I think it is more accurate to use Optional[List[nodes.NodeNG]]
since the nodes which are unpacked won't necessarily be of type nodes.AssignName
(they could be a list of node.Const nodes, for example in the case of x, y, z = 1, 2, 3
).
Moreover we can make the function name more accurate (_nodes_to_unpack
?) & the type of the parameter should be nodes.NodeNG
since this value originates from the returned value of the safe_infer
method.
@@ -42,6 +42,14 @@ Release date: TBA | |||
|
|||
Closes #5281 | |||
|
|||
* Fix false positive - Allow unpacking of ``self`` in a subclass of ``typing.NamedTuple``. |
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.
Just for the commit history I would be better to leave this where it currently is, right? This is not a blocking issue for me though.
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.
Thank you @mbyrnepr2 , great addition to 2.13 !
Type of Changes
Description
Closes #5707