Skip to content

Commit

Permalink
Merge pull request #635 from google/google_sync
Browse files Browse the repository at this point in the history
When raising not-supported-yet for Alias = Union[T, ...] set the type…
  • Loading branch information
rchen152 committed Jul 30, 2020
2 parents 95e5e8f + 7f0b940 commit 75e64fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pytype/tests/py3/test_typevar.py
Expand Up @@ -415,12 +415,11 @@ def f(x: T) -> T:

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 f(x: Tree[int]): ... # no error since Tree is set to Any
""")


Expand Down
7 changes: 5 additions & 2 deletions pytype/vm.py
Expand Up @@ -1287,11 +1287,13 @@ def store_global(self, state, name, value):
"""Same as store_local except for globals."""
return self._store_value(state, name, value, local=False)

def _check_aliased_type_params(self, value):
def _check_for_aliased_type_params(self, value):
for v in value.data:
if isinstance(v, abstract.Union) and v.formal:
self.errorlog.not_supported_yet(
self.frames, "aliases of Unions with type parameters")
return True
return False

def _remove_recursion(self, node, name, value):
"""Remove any recursion in the named value."""
Expand Down Expand Up @@ -1374,7 +1376,8 @@ def _pop_and_store(self, state, op, name, local):
value = self._apply_annotation(
state, op, name, orig_val, annotations_dict, check_types)
value = self._remove_recursion(state.node, name, value)
self._check_aliased_type_params(value)
if self._check_for_aliased_type_params(value):
value = self.new_unsolvable(state.node)
state = state.forward_cfg_node()
state = self._store_value(state, name, value, local)
self.trace_opcode(op, name, value)
Expand Down

0 comments on commit 75e64fb

Please sign in to comment.