-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive: not-callable
for property that returns a lambda function conditionally
#5931
Comments
This requires understanding of control flow as we can't infer that the return value of Note that class C:
def __init__(self):
self._x = lambda: None
@property
def foo(self):
return self._x
c = C()
c.foo() |
not-callable
not-callable
for property that returns a lambda function conditionally
@DanielNoord Somehow the class C:
def __init__(self):
self._x = None
def foo(self):
if self._x is None:
self._x = lambda: None
return self._x
c = C()
c.foo()() Doing So it seems that the control flow analysis is already present and working. There's just some edge case with properties. |
Yeah, the code that checks this relies on the |
If control flow wasn't there, my 2nd example should've also raised E1102 right? |
In the second example the outer For the inner I haven't thought about the implications of that first check, but perhaps that is a little too restrictive. That said, I think we're (correctly) being a little stricter when we find the We could obviously be less strict until we have better control-flow (at some point...), but is that worth it? I don't know your use case, but doesn't initialising to the empty |
Found this: The inference seems to work just fine. Here, But since we're checking if Even if some of the inferred results are callable, pylint reports that it is not callable. Instead of that, maybe it should raise "possibly-not-callable"? |
Proposed solution:
|
@tushar-deepsource What about changing |
@DanielNoord sounds good to me! Did you mean "assigning non callable to callable"? As in if a variable has multiple possible values and some of them aren't callable. |
Yeah! I think we should exclude |
I'll make a new issue for that. For this issue, is it okay to not raise |
@tushar-deepsource I think that sounds like the right way forward! |
Bug description
Configuration
No response
Command used
pylint myfile.py | grep E1102
Pylint output
Expected behavior
No error. The code runs when run under python.
Pylint version
OS / Environment
MacOS Monterey
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: