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

Forbid incorrect __slots__ names #696

Closed
sobolevn opened this issue Jul 21, 2019 · 1 comment
Closed

Forbid incorrect __slots__ names #696

sobolevn opened this issue Jul 21, 2019 · 1 comment
Assignees
Labels
help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule

Comments

@sobolevn
Copy link
Member

Rule request

Thesis

We need to lint names in slots. Rules are:

  • names are non-empty
  • they should be valid python identifiers
  • they should have valid attribute names (snake_case) we can reuse logic from pep8-naming

Reasoning

Otherwise names defined in __slots__ will be incorrect and will result in incorrect objects.
This is OOP rule

@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule labels Jul 21, 2019
@sobolevn sobolevn added this to the Version 0.12.0 milestone Jul 21, 2019
@sobolevn
Copy link
Member Author

By the way, python already handles this case:

class Test(object):
    a = 1

    __slots__ = ('a', 'b')

Will result in:

Traceback (most recent call last):
  File "ex.py", line 1, in <module>
    class Test(object):
ValueError: 'a' in __slots__ conflicts with class variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

1 participant