Skip to content

Commit

Permalink
Fix a crash caused by a variable having no bindings.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 265961535
  • Loading branch information
rchen152 committed Aug 28, 2019
1 parent b70b072 commit fca9a22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pytype/abstract.py
Expand Up @@ -2347,7 +2347,8 @@ def update_sig(method):
mbr, default=self.vm.convert.unsolvable)
if isinstance(m, InterpreterFunction):
update_sig(m)
elif all(x.__class__.__name__ == "PropertyInstance" for x in mbr.data):
elif mbr.data and all(
x.__class__.__name__ == "PropertyInstance" for x in mbr.data):
# We generate a new variable every time we add a property slot, so we
# take the last one (which contains bindings for all defined slots).
prop = mbr.data[-1]
Expand Down
13 changes: 13 additions & 0 deletions pytype/tests/py3/test_classes.py
Expand Up @@ -194,6 +194,19 @@ class Foo(object):
bar: int
""")

def testGenericSuper(self):
self.Check("""
from typing import Callable, Generic, TypeVar
T = TypeVar('T')
Func = Callable[[T], str]
class Foo(Generic[T]):
def __init__(self, func: Func = str) -> None:
super(Foo, self).__init__()
self._func = func
def f(self, value: T) -> str:
return self._func(value)
""")


class ClassesTestPython3Feature(test_base.TargetPython3FeatureTest):
"""Tests for classes."""
Expand Down

0 comments on commit fca9a22

Please sign in to comment.