You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing an endless recursion (apparently, from the trace, not the same as this currently open issue). Consider this snippet:
v = bool() or 1
When I infer the value of v, the execution gets to a point where it bounces back and forth between def _infer_method_result_truth and def bool_value. Eventually, the maximum recursion limit is reached.
I believe that the root cause of the problem is here: due to bool(), we have the inferred object as being the "same" as the instance object (an instance of class bool). I suppose that a check* must be added there, for this equality.
*I could create a PR, but it seems that Instance has no __eq__ method; I could still check with if (str(inferred) == str(instance): return util.Uninferable but I'm not sure it'd be corred/desired.
NOTE: The same issue happens in slight variations, e.g., v = w if hasattr(o, 'x') else 1
The text was updated successfully, but these errors were encountered:
ltcmelo
changed the title
endless recursion checking the bool_value of a condition which value bool()
endless recursion checking the bool_value of a condition with value bool()Jan 4, 2021
@ltcmelo thanks for your report.
I'm am currently unable to reproduce it.
Can you give a snippet of the problematic code and the version of python and astroid you are using?
not always the recursion is infinite, there appears to exists a co-relation with the files/project being processed; I couldn't spot what is breaking the recursion, though — I suspect that, in certain cases, the context object passed to infer will aggregate enough info, but those cases don't seem to be guaranteed.
even with a limited recursion, it's still possible to observe (what I believe is) the bogus behavior I mentioned.
A list of steps that you could try in order to validate my suspicion. Perhaps, you could try reducing your sys.setrecursionlimit too…
Create a regular AST visitor, load a module with that snippet I originally suggested, and, upon visit_name, call node.infer on object corresponding to v.
I expect that you see tens of calls jumping back and forth between those 2 methods, repeatedly trying to infer the samebool instance. This is how my prints look like.
Python version: Python 3.8.6 (CPython on darwin)
astroid: 2.4.2
I'm facing an endless recursion (apparently, from the trace, not the same as this currently open issue). Consider this snippet:
When I
infer
the value ofv
, the execution gets to a point where it bounces back and forth between def _infer_method_result_truth and def bool_value. Eventually, the maximum recursion limit is reached.I believe that the root cause of the problem is here: due to
bool()
, we have theinferred
object as being the "same" as theinstance
object (an instance of class bool). I suppose that a check* must be added there, for this equality.*I could create a PR, but it seems that
Instance
has no__eq__
method; I could still check withif (str(inferred) == str(instance): return util.Uninferable
but I'm not sure it'd be corred/desired.NOTE: The same issue happens in slight variations, e.g.,
v = w if hasattr(o, 'x') else 1
The text was updated successfully, but these errors were encountered: