Allow some single uppercase letter function arguments and-or local variables
The use of single uppercase letter variables is pretty widespread in some applications, namely those that are more math-oriented. For example, X is a common variable name given to a matrix, G for graphs, etc.
My understanding of PEP8 is that these are specifically allowed (see Names to avoid), but also not specifically disallowed in the more relevant Function and method arguments section, which lists only N804 and N805.
I think we could make an exception to N806 for single-letter variable names. It would also be easy to implement.
What do the other @PyCQA/pep8-naming-dev folks think about this?
The cited sentence is:
Never use the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), or 'I' (uppercase letter eye) as single character variable names.
I would say it's a misinterpretation that it explicitly disallowing single upper case variable names for certain letters, is it implicitly allowing of other letters as upper case to be used as variables.
I think the case where the cited reason comes into effect are cases like class E: (allowed) vs class I: (disallowed).
Instead of special-casing single letters for this specific use case, unless there's good evidence that this is a really common naming pattern, I think we should recommend:
-
--ignore-namesfor code bases whereXandGlike OP suggested are common. - use per-line disabling like
X = 3 # noqa: N806in codebases where it is uncommon
- use per-line disabling like
X = 3 # noqa: N806in codebases where it is uncommon
This suggestion unfortunately isn't great for function argument names, which are relevant to this use case:
def scale_matrix(M, scalar):
... because it would suppress N806 for all names on that line, which could be overly blunt.