Open eqvinox opened 1 year ago
Ping?
This feels like it is pytest
specific right? In that case I think it makes more sense to put this in a pytest
plugin.
This feels like it is
pytest
specific right? In that case I think it makes more sense to put this in apytest
plugin.
It's not pytest specific, I just wanted to give the real-world use case that caused me to bump into this. The reproduction script above doesn't use pytest. There is no get
that you can call instead of __get__
on a descriptor. Anything working with descriptors on an advanced level can/will run into this.
Sorry I misread. I think the main issue here is that we can't really infer the type of method_ref
. This feels like such an edge case that I would argue that disabling the message here is better than not raising it ever for __get__
.
I don't think there's another __get__
that the warning is useful for? AFAIK __get__
__set__
and __delete__
are specific to descriptors; if you're calling them you likely have no other choice — at least that's my understanding…
Double checking with https://docs.python.org/3/genindex-_.html - there is no other use of those 3 dunder methods, they're only used on descriptors.
@jpy-git as the implementer of the check what do you think ?
Random ping to keep this alive - @jpy-git ?
To rephrase/repeat my understanding: __get__
(and __set__
and __delete__
) dunder methods only exist on descriptors, and have no non-dunder replacement, thus there is no warning that makes sense for these 3 dunder methods. (The Use get method.
part of the warning could in fact be harmful to up-and-learning developers on first encountering python descriptors — there is no "get" method on descriptors.)
I agree with @eqvinox. At the very least, this is a bug in the warning message because it is recommending that the developer use an alternative (use the get
method) that doesn't exist. And if you are going to fix the warning message for these three dunder methods, it might be best to just eliminate the warning altogether, since the lack of an alternative means that the use of the dunder method is not, in fact, unnecessary.
Bug description
When converting an unbound method (on a class) to a bound method (on an object) by calling
__get__
, pylint emits anunnecessary-dunder-call
warning:The use case of this is in pytest, class attributes are scanned for test case methods first (without an instance) and then later bound to an instance of their class.
To my knowledge (happy to be proven wrong?), the descriptor dunder methods (
__get__
,__set__
,__delete__
) don't have any other way of being invoked, there is noget
/set
/delete
. So they should be ignored for the dunder warning.Command used
Pylint output
Expected behavior
No warning.
Pylint version
OS / Environment
Debian unstable