1
0
forked from VimPlug/jedi

Fix an mro resolution issue.

This commit is contained in:
Dave Halter
2015-02-23 19:04:35 +01:00
parent a91e240c8b
commit 4f2d4992da
3 changed files with 47 additions and 9 deletions

View File

@@ -404,8 +404,24 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
for cls in self.py__bases__(self._evaluator):
# TODO detect for TypeError: duplicate base class str,
# e.g. `class X(str, str): pass`
try:
mro_method = cls.py__mro__
except AttributeError:
# TODO add a TypeError like:
"""
>>> class Y(lambda: test): pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function() argument 1 must be code, not str
>>> class Y(1): pass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int() takes at most 2 arguments (3 given)
"""
pass
else:
add(cls)
for cls_new in cls.py__mro__(evaluator):
for cls_new in mro_method(evaluator):
add(cls_new)
return tuple(mro)
@@ -443,7 +459,14 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
def get_subscope_by_name(self, name):
for s in [self] + self.py__bases__(self._evaluator):
for sub in reversed(s.subscopes):
try:
subscopes = s.subscopes
except AttributeError:
# TODO look at the __mro__ todo, we should add a TypeError
# here.
pass
else:
for sub in reversed(subscopes):
if sub.name.value == name:
return sub
raise KeyError("Couldn't find subscope.")

View File

@@ -174,7 +174,6 @@ class ParserNode(object):
Closes the current parser node. This means that after this no further
nodes should be added anymore.
"""
#print('CLOSE NODE', id(self), self.parent, self._node_children)
# We only need to replace the dict if multiple dictionaries are used:
if self._node_children:
dcts = [n.parser.module.names_dict for n in self._node_children]
@@ -398,7 +397,6 @@ class FastParser(use_metaclass(CachedFastParser)):
debug.dbg('While parsing %s, line %s slowed down the fast parser.',
self.module_path, line_offset + 1)
print(line_offset, repr(code_part))
line_offset = next_line_offset
start += len(code_part)

View File

@@ -450,9 +450,26 @@ class TestX(object):
# -----------------
class A(object):
pass
a = 3
#? ['mro']
A.mro
#? []
A().mro
# -----------------
# mro resolution
# -----------------
class B(A()):
b = 3
#?
B.a
#?
B().a
#? int()
B.b
#? int()
B().b