Skip to content

Commit

Permalink
FIX: We were occasionally reusing an exhausted generator in Union con…
Browse files Browse the repository at this point in the history
…structor.

PiperOrigin-RevId: 323697283
  • Loading branch information
martindemello authored and rchen152 committed Jul 29, 2020
1 parent 4447970 commit ceeb07f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytype/abstract.py
Expand Up @@ -1435,7 +1435,7 @@ def __init__(self, options, vm):
assert options
self.options = list(options)
# TODO(rechen): Don't allow a mix of formal and non-formal types
self.formal = any(t.formal for t in options)
self.formal = any(t.formal for t in self.options)
mixin.NestedAnnotation.init_mixin(self)

def __repr__(self):
Expand Down
10 changes: 10 additions & 0 deletions pytype/tests/test_typevar.py
Expand Up @@ -419,6 +419,16 @@ def test_recursive_alias(self):
""")
self.assertErrorRegexes(errors, {"e": r"Recursive.*X"})

def test_use_unsupported_typevar(self):
# Test that we don't crash when using this pattern (b/162274390)
# Note that it throws four distinct errors, which is less than ideal.
self.CheckWithErrors("""
from typing import List, TypeVar, Union
T = TypeVar("T")
Tree = Union[T, List['Tree']] # not-supported-yet # not-supported-yet
def f(x: Tree[int]): ... # invalid-typevar # unsupported-operands
""")

def test_type_of_typevar(self):
self.Check("""
from typing import Sequence, TypeVar
Expand Down

0 comments on commit ceeb07f

Please sign in to comment.