wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Enforce `x`, `x1`,` x2` naming consistency
Rule request
Thesis
I often see that some people use this naming pattern:
x1 = 1
x2 = 2
Which is perfectly fine. But, this one looks ugly:
x = 1
x2 = 2
Note x1
vs x2
difference.
Reasoning
My proposed solution is to create a new naming rule to check that if a variable named something1
or something2
there should not be just something
in the current scope. While just something
and something1
with something2
are totally fine.
Our own code will have lots of these issues!
I would say that any numbered name should trigger a violation on unnumbered one.
Hi, I'd like to claim this issue.
Thanks a lot, @raghul-rajasekar!
Hi, I am a Umich student and would like to work on this issue for one of my class assignments!
I have a question regarding the rule:
Would just having something like x2 = 2
(without x1 = 1
) count as violating the rule?
No, any names with a context are fine. We only look for this pattern:
x = 1
x2 = 2
Thanks a lot, assigned! Feel free to ask for any help you need 👍
Might also want to consider checking for underscores:
x = 1
x_2 = 2
I am wondering: what context should we care about? One function? Or the whole module?
Ok, I am going to only check for names in the same context. Whatever it might be: function, class, module.
Ok, this is hard. There are lots of corner cases and small things to think about.
For example, attributes need special handling:
-
some.x
andsome.x2
are violating this rule - while
some.x
andother.x2
are not
So, I am moving this feature for the next version.