Skip to content

Avoid infinite recursion in type queries #5434

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

Merged
merged 1 commit into from
Aug 8, 2018

Conversation

ilevkivskyi
Copy link
Member

Fixes #5357
Fixes #4780

This might potentially fix similar crashes on recursive types.

@ilevkivskyi ilevkivskyi requested a review from msullivan August 8, 2018 17:29
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -1915,6 +1915,7 @@ class TypeQuery(SyntheticTypeVisitor[T]):

def __init__(self, strategy: Callable[[Iterable[T]], T]) -> None:
self.strategy = strategy
self.seen = [] # type: List[Type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How big do we expect seen to get? If we think it will get pretty big we could make it a set of ids of Typess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My expectation is that seen should be never larger than few dozens of types. I think we discussed this with @JukkaL when implementing ForwardReferenceResolver that uses the same pattern and decided it is "small" (whatever it means).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ilevkivskyi ilevkivskyi merged commit ca201f4 into python:master Aug 8, 2018
@ilevkivskyi ilevkivskyi deleted the fix-recursive-crashes branch August 8, 2018 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypedDict RecursionError Crash on recursive NamedTuple definition
2 participants