-
-
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
CallContext assertion failed in the wild #9214
Comments
Here's a more minimal example: import astroid
text = """
import functools
class MockClass:
def _get_option(self, option):
return "mystr"
enabled = property(functools.partial(_get_option, option='myopt'))
MockClass().enabled #@
"""
print(astroid.extract_node(text).inferred()) I can confirm that this has something to do with the Unsure where/how this call context should be set, should we remove this assertion? |
Thanks for the reproducer. I think removing the assertion won't help; it would just crash on the next line.
Based on this, I wonder if we can do something like: diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py
index cad91dcf..efd5439b 100644
--- a/astroid/nodes/scoped_nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes/scoped_nodes.py
@@ -2518,6 +2518,10 @@ class ClassDef( # pylint: disable=too-many-instance-attributes
elif isinstance(inferred, objects.Property):
function = inferred.function
if not class_context:
+ if not context.callcontext:
+ context.callcontext = CallContext(
+ args=function.args.arguments, callee=function
+ )
# Through an instance so we can solve the property
yield from function.infer_call_result(
caller=self, context=context |
…function. Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case.
…function. (#2458) Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case. (cherry picked from commit 0f9dfa6)
…function. (#2458) Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case. (cherry picked from commit 0f9dfa6)
…function. (#2458) (#2460) Closes pylint-dev/pylint#9214 Thanks Martin Belanger for the report and Bryce Guinta for the test case. (cherry picked from commit 0f9dfa6) Co-authored-by: Jacob Walls <[email protected]>
I wrote a simple mock module (below) to show the problem. The code executes fine with Python 3.10. However,
pylint
throws an exception (log below) when parsing it. I updatedpylint
today from 2.17.5 to 3.0.2. That's when it started to fail.Note: This was run on Ubuntu 22.04 with Python 3.10.
Pylint version that was working OK:
Pylint version that is not working:
Mock module:
This is pylint's output:
The text was updated successfully, but these errors were encountered: