Skip to content

Commit

Permalink
Don't crash when looking up a name in class scope after MRO error.
Browse files Browse the repository at this point in the history
Fixes #2001.
  • Loading branch information
Guido van Rossum committed Aug 9, 2016
1 parent d59b74d commit 28e2652
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ def lookup(self, name: str, ctx: Context) -> SymbolTableNode:
return None
# 2. Class attributes (if within class definition)
if self.is_class_scope() and name in self.type.names:
return self.type[name]
return self.type.names[name]
# 3. Local (function) scopes
for table in reversed(self.locals):
if table is not None and name in table:
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -2059,3 +2059,9 @@ class B(A): pass
class C(B): pass
class D(A, B): pass # E: Cannot determine consistent method resolution order (MRO) for "D"
class E(C, D): pass # E: Cannot determine consistent method resolution order (MRO) for "E"

[case testInconsistentMroLocalRef]
class A: pass
class B(object, A): # E: Cannot determine consistent method resolution order (MRO) for "B"
def readlines(self): pass
__iter__ = readlines

0 comments on commit 28e2652

Please sign in to comment.