class MyClass(object):
"""My class."""
subs = MyClass.__subclasses__()
This piece of code raises
WPS609 Found direct magic attribute usage: __subclasses__
__subclasess__ method should be excluded from the check because it's a class method and can be used outside of class.
Maybe there are other methods that should be excluded?
__name__?
__name__ doesn't raise violation 馃榿
But it should be excluded too, of course.
Hi, I have never contributed to an open-source project before but I would like to start here :) I have already forked the repository and cloned it.
This is probably really dumb but I am having trouble understanding in what file this actual bug resides.
cheers
@mattany thanks a lot! And congrats on your first open-source fork 馃帀
I am going to help you!
And let's start from here: we can create a whitelist of method names that can be called.
And do not raise violation if this method name is inside the whitelist.
Feel free to ask any questions!
Thank you! I noticed that in attributes.py there is already a whitelist like what you suggested:
_allowed_magic_attributes: ClassVar[FrozenSet[str]] = frozenset((
'__class__',
'__name__',
'__qualname__',
'__doc__',
))
It already includes __name__ but doesn't include __subclasses__. I can't think of any other magic methods/attributes that should be called directly in some contexts, but I believe that adding __subclasess__ to the set above would fix this specific issue. If other false positives arise they can also be added there.
Should I add it and send a pull request?
On the same subject, perhaps the excluded ones should be called from certain contexts and not from others? If there are contexts from which they too shouldn't be accessed directly, perhaps there is a way to discern between the 'good' and 'bad' calls? Just thought I would share in case we can make the exception even better.
Let's also add __mro__ to the list and it's done!
Great. I issued a pull request. Hope I did it right 馃槃
@sobolevn @mattany found the new one - __version__
@AlwxSin submit a PR then 馃浄