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
1824 add getting first element using unpacking violation #1927
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1927 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 120 120
Lines 6377 6394 +17
Branches 1421 1424 +3
=========================================
+ Hits 6377 6394 +17
Continue to review full report at Codecov.
|
""" | ||
|
||
error_template = 'Found incorrect unpacking target' |
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 message is identical to WrongUnpackingViolation.error_template
, let's change it to something more related to this violation, e.g.:
error_template = 'Found incorrect unpacking target' | |
error_template = 'Found wrong retrieving of the first element' |
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.
Thanks, I forget to fix this after copy-paste. Done.
CHANGELOG.md
Outdated
|
||
### Features | ||
|
||
* Forbids getting first element of list by unpacking |
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.
-
, not *
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.
Done.
Maybe if the project have MD style rules, it can use some linter? I found rule that seems to fix bullet list style: https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md#md004---unordered-list-style
I may work on adding linter to the project.
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.
You can check markdown-lint
action by reviewdog
- https://github.com/reviewdog/action-markdownlint
len(targets) == 2 and | ||
isinstance(targets[0], ast.Name) and | ||
isinstance(targets[1], ast.Starred) and | ||
_is_unused_variable_name(targets[1].value) |
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.
Let's refactor this part to use: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/logic/naming/access.py#L9
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.
@sobolevn I would like too, but in "Feedback" section of PR I described, why this do not works.
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.
Oh, sorry. Let's use is_protected
then
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 not work too:
>>> is_protected('_')
False
>>> is_protected('__')
False
While access.is_unused(node.id) or access.is_protected(node.id)
works.
But for me such code looks misleading. Would you consider adding different "weak" kind of is_unused
in naming.access?
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.
Ok, then let's create a new function access.looks_like_unused()
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.
Done.
I have made things!
This code only checks unpacking for variable assignment case outlined in issue.
I do not cover cases like
for a, *_r in smthg
ora, *_b, *_c
because it seems unlikely that somebody will use them.If you think that my assumption is not correct, I will update the code.
Checklist
CHANGELOG.md
Related issues
Feedback
The function
logic.naming.access.is_unused
uses the term "unused" differently. It says that_rest
is not unused, but "private" name, while in issue such name is classified as unused.Related code uses term
target
in two different senses.One is for
target1 = target2 = ...
, the same like ast module does.Second one is for `target1, target2 = ...', which conflicts with first sence.
I think that renaming second thing will clarify situation.