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

Restrict protected attributes and methods access and assignment #272

Closed
sobolevn opened this issue Oct 17, 2018 · 0 comments
Closed

Restrict protected attributes and methods access and assignment #272

sobolevn opened this issue Oct 17, 2018 · 0 comments
Labels
Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:advanced Needs a lot of care rule request Adding a new rule
Milestone

Comments

@sobolevn
Copy link
Member

Rule request

Thesis

Currently we allow to use this code:

bad = object()
bad._protected = 1
print(bad._protected)

No warning would be shown to the user.

What we need to do?

  1. We need to forbid to use protected names (that are starting with _) in a free manner
  2. These attributes and methods can not be: called, assigned, accessed from outer scope
  3. But, they can be used freely with self and cls like: self._some = 1
  4. This example should also be valid:
class Test(object): 
      _some = 1
      _extra_some = _some + 2

However, Test._some is not valid.

Reasoning

We should respect protected APIs. And whenever we are using one (which we should not do), we should explicitly mark these lines with noqa.

@sobolevn sobolevn added help wanted Extra attention is needed rule request Adding a new rule Hacktoberfest Hactoberfest fun! level:advanced Needs a lot of care labels Oct 17, 2018
@sobolevn sobolevn added this to the Version 0.3.0 milestone Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:advanced Needs a lot of care rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

1 participant