Wemake-python-styleguide: WPS434 on tuple conversion

Created on 5 Jan 2021  路  4Comments  路  Source: wemake-services/wemake-python-styleguide

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.

bug

All 4 comments

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.

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.

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobolevn picture sobolevn  路  4Comments

Dreamsorcerer picture Dreamsorcerer  路  4Comments

sobolevn picture sobolevn  路  4Comments

sobolevn picture sobolevn  路  4Comments

webknjaz picture webknjaz  路  3Comments