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

Think about direct magic method invocation #494

Closed
sobolevn opened this issue Feb 17, 2019 · 3 comments
Closed

Think about direct magic method invocation #494

sobolevn opened this issue Feb 17, 2019 · 3 comments
Assignees
Labels
question Further information is requested rule request Adding a new rule

Comments

@sobolevn
Copy link
Member

Rule request

Thesis

Some users say that d.__delitem__('a') should not be used. And it is perfectly reasonable, since both del and __delitem__ magic method are restricted.

But, this maid me think about general case: should we allow to call magic methods directly?

Reasoning

We already disallow to use protected attributes and methods. This might be similar.
But, we need to think about all possible cases like .__dict__, .__mro__, etc.

So, there are two way to go:

  1. Forbid to use all forbidden magic method calls from the instance: d.__delitem__('a')
  2. Forbid to use any magic methods directly (need deeper investigation)
@sobolevn sobolevn self-assigned this Feb 17, 2019
@sobolevn sobolevn added question Further information is requested rule request Adding a new rule labels Feb 17, 2019
@sobolevn
Copy link
Member Author

From my research I have not found any valid magic attributes in all my source code.
Even if there are any direct magic method invocations - then it should be marked as noqa.

@sobolevn
Copy link
Member Author

sobolevn commented Feb 26, 2019

Hm, nope. There's a whitelist: __class__, __name__, __qualname__, __doc__.
Link: https://docs.python.org/3/reference/datamodel.html

@sobolevn
Copy link
Member Author

Just a better listing: https://rszalski.github.io/magicmethods/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

1 participant