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
{{ message }}
Repository navigation
Infinite recursion with typing.get_type_hints #81987
get_type_hints(A, globals(), locals())
This reaches the recursion limit as of 3.8.0b2.
It seems that the combining _GenericAlias with ForwardRef is what triggers this condition:
ForwardRef._evaluate sets __forward_value__ on its first call on a given instance
_GenericAlias tries to compare its args post evaluation
If one of the arguments is a previously evaluated forward reference containing a cycle, then it will infinitely recurse in the hash function when building a frozen set for the comparison.
The above is, of course, a very artificial example, but I can imagine this happening a lot in code with trees or similar structures.
My initial reproduction case was using _eval_type to resolve forward references returned by get_args (side note: it would be nice to have a public function to do that).
Activity
vg0377467 commentedon Aug 10, 2019
I encountered one condition where calling get_type_hints causes infinite recursion when dealing with forward declaration and cyclic types.
Here's an example:
get_type_hints(A, globals(), locals())
This reaches the recursion limit as of 3.8.0b2.
It seems that the combining _GenericAlias with ForwardRef is what triggers this condition:
ForwardRef._evaluate sets __forward_value__ on its first call on a given instance
_GenericAlias tries to compare its args post evaluation
If one of the arguments is a previously evaluated forward reference containing a cycle, then it will infinitely recurse in the hash function when building a frozen set for the comparison.
The above is, of course, a very artificial example, but I can imagine this happening a lot in code with trees or similar structures.
My initial reproduction case was using _eval_type to resolve forward references returned by get_args (side note: it would be nice to have a public function to do that).
hongweipeng commentedon Sep 14, 2019
This report can be closed, PR bpo-15400 has solved this issue.
hongweipeng commentedon Sep 14, 2019
Sorry, the link is #15400 .