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

WPS434 on tuple conversion #1807

Closed
vnmabus opened this issue Jan 5, 2021 · 4 comments · Fixed by #2070
Closed

WPS434 on tuple conversion #1807

vnmabus opened this issue Jan 5, 2021 · 4 comments · Fixed by #2070
Assignees
Labels
bug Something isn't working

Comments

@vnmabus
Copy link

vnmabus commented Jan 5, 2021

Bug report

What's wrong

A WPS434: Found reassigning variable to itself violation is raised for the following code:

my_var = (my_var,)

How it should be

As the code replaces the original object with a tuple containing it, the line is not a simple reasignation. Thus, the violation WPS434 should not be raised.

@vnmabus vnmabus added the bug Something isn't working label Jan 5, 2021
@orsinium
Copy link
Collaborator

orsinium commented Jan 11, 2021

FYI, MyPy won't be happy with this code as well unless you have allow_redefinition enabled. So, probably it's worth making a new variable here.

@vnmabus
Copy link
Author

vnmabus commented Jan 11, 2021

It seems that redefinitions that narrow the original type are ok in Mypy. In my case this code is being used for a variable that can be either a tuple or an individual element, converting it into a one element tuple in that case. Mypy does not complain even with strict flags enabled, and reveal_type reflects the type narrowing correctly.

@sobolevn
Copy link
Member

sobolevn commented Feb 6, 2021

I would leave this as wontfix, because this is a very special case.
I would recommend to:

  • Use noqa for this line
  • Use other variable name

@sobolevn sobolevn closed this as completed Feb 6, 2021
@vnmabus
Copy link
Author

vnmabus commented Feb 8, 2021

The same problem happens if you do my_var = (my_var, my_var). I know you said you will not fix it, but just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants