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

Allow some single uppercase letter function arguments and-or local variables #7

Open
pedros opened this issue Jan 2, 2014 · 3 comments

Comments

@pedros
Copy link

pedros commented Jan 2, 2014

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.

@jparise
Copy link
Member

jparise commented Jan 2, 2020

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?

@saifelse
Copy link
Contributor

saifelse commented Jan 2, 2020

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-names for code bases where X and G like OP suggested are common.
  • use per-line disabling like X = 3 # noqa: N806 in codebases where it is uncommon

@jparise
Copy link
Member

jparise commented Jan 2, 2020

  • use per-line disabling like X = 3 # noqa: N806 in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants