Skip to content

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

Merged

Conversation

mbyrnepr2
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix
✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Closes #5707

@coveralls
Copy link

coveralls commented Jan 23, 2022

Pull Request Test Coverage Report for Build 1769225036

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 93.879%

Totals Coverage Status
Change from base Build 1768037003: 0.001%
Covered Lines: 14770
Relevant Lines: 15733

πŸ’› - Coveralls

@DanielNoord DanielNoord self-requested a review January 23, 2022 19:20
Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Small question(s) πŸ˜„

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative πŸ¦‹ No message is emitted but something is wrong with the code label Jan 24, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 24, 2022
@Pierre-Sassoulas Pierre-Sassoulas self-requested a review January 24, 2022 22:41
@mbyrnepr2 mbyrnepr2 requested a review from DanielNoord January 25, 2022 21:08
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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

@@ -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]:
Copy link
Collaborator

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:

Suggested change
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List]:
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List[nodes.AssignName]]:

Or:

Suggested change
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List]:
def _get_values_to_unpack(node: nodes.Assign) -> Optional[List[nodes.NodeNG]]:

Copy link
Member Author

@mbyrnepr2 mbyrnepr2 Jan 30, 2022

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``.
Copy link
Collaborator

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.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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 !

@Pierre-Sassoulas Pierre-Sassoulas merged commit ef67460 into pylint-dev:main Feb 2, 2022
@mbyrnepr2 mbyrnepr2 deleted the 5707_false_negative_tuple_unpacking branch February 2, 2022 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative - tuple unpacking & empty list
4 participants