Skip to content

Avoid infinite recursion in type queries - #5434

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-recursive-crashes
Aug 8, 2018
Merged

Avoid infinite recursion in type queries#5434
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-recursive-crashes

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Fixes#5357
Fixes#4780

This might potentially fix similar crashes on recursive types.

@msullivanmsullivan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

Comment threadmypy/types.py

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

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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:masterAug 8, 2018
@ilevkivskyi
ilevkivskyi deleted the fix-recursive-crashes branch August 8, 2018 23:45
Sign up for freeto 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

@ilevkivskyi@msullivan