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

Add naming rule for instance variables #216

Open
chjaesch opened this issue May 2, 2023 · 2 comments
Open

Add naming rule for instance variables #216

chjaesch opened this issue May 2, 2023 · 2 comments

Comments

@chjaesch
Copy link

chjaesch commented May 2, 2023

Regarding to the PEP8 namely conventions, method names and instance variables shall pass the function naming rules (lowercase with words separated by underscore): https://peps.python.org/pep-0008/#method-names-and-instance-variables
Therefore, it would be beneficial to regard this in pep8-naming by adding an naming rule for instance variables, similar to N806.

For example, self._fooVariable in

class AClass:

    def __init__(self) -> None:
        self._fooVariable = 42

should be reported.

@sigmavirus24
Copy link
Member

I believe this has been discussed in depth before. The short answer as to why this is hard is that subclassing something using camelcase variables then will cause pep8-naming to flag that usage as well as it's indistinguishable from the example you gave. The rate of false positives would be too high and we don't execute code to be able to determine if an instance attribute is defined for the first time in the scope we see it or if it comes from a parent

@chjaesch
Copy link
Author

chjaesch commented May 2, 2023

Regarding PEP8 conventions, using CamelCase for variables in a parent class would also not be correct.
Therefore, it would be consistent to mark it as an error if it were used in a child class. If it is implemented as an individual naming rule, the user can suppress this if necessary.
Otherwise, the non-use of "lower_case_with_underscores" will not be sanctioned and will continue in the future.

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

No branches or pull requests

2 participants