The Wayback Machine - https://web.archive.org./web/20220511032349/https://github.com/wemake-services/wemake-python-styleguide/pull/1927
Skip to content
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

Merged
merged 4 commits into from on Dec 13, 2021

Conversation

uhbif19
Copy link
Contributor

@uhbif19 uhbif19 commented on Mar 7, 2021

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 or a, *_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

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the 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.

Sorry, something went wrong.

@uhbif19 uhbif19 changed the title Closes #1880 1880 add getting first element using unpacking violation on Mar 7, 2021
@codecov
Copy link

@codecov codecov bot commented on Mar 7, 2021

Codecov Report

Merging #1927 (781cefd) into master (e558965) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1927   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          120       120           
  Lines         6377      6394   +17     
  Branches      1421      1424    +3     
=========================================
+ Hits          6377      6394   +17     
Impacted Files Coverage Δ
wemake_python_styleguide/logic/naming/access.py 100.00% <100.00%> (ø)
wemake_python_styleguide/logic/tree/variables.py 100.00% <100.00%> (ø)
...ake_python_styleguide/violations/best_practices.py 100.00% <100.00%> (ø)
wemake_python_styleguide/visitors/ast/builtins.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e558965...781cefd. Read the comment docs.

@uhbif19 uhbif19 changed the title 1880 add getting first element using unpacking violation 1824 add getting first element using unpacking violation on Mar 8, 2021
"""

error_template = 'Found incorrect unpacking target'
Copy link
Collaborator

@skarzi skarzi on Mar 9, 2021

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.:

Suggested change
error_template = 'Found incorrect unpacking target'
error_template = 'Found wrong retrieving of the first element'

Copy link
Contributor Author

@uhbif19 uhbif19 on Mar 10, 2021

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.

Copy link
Member

@sobolevn sobolevn left a comment

Thanks a lot!

CHANGELOG.md Outdated

### Features

* Forbids getting first element of list by unpacking
Copy link
Member

@sobolevn sobolevn on Mar 10, 2021

Choose a reason for hiding this comment

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

-, not *

Copy link
Contributor Author

@uhbif19 uhbif19 on Mar 10, 2021

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.

Copy link
Collaborator

@skarzi skarzi on Mar 10, 2021

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)
Copy link
Member

@sobolevn sobolevn on Mar 10, 2021

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@uhbif19 uhbif19 on Mar 10, 2021

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.

Copy link
Member

@sobolevn sobolevn on Mar 10, 2021

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

Copy link
Contributor Author

@uhbif19 uhbif19 on Mar 10, 2021

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?

Copy link
Member

@sobolevn sobolevn on Mar 10, 2021

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()

Copy link
Contributor Author

@uhbif19 uhbif19 on Mar 11, 2021

Choose a reason for hiding this comment

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

Done.

@sobolevn sobolevn added this to the Version 0.16 milestone on Mar 12, 2021
Copy link
Collaborator

@skarzi skarzi left a comment

great work!

@sobolevn sobolevn merged commit 9faaef0 into wemake-services:master on Dec 13, 2021
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants