mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
fix mro usage and all the type stuff (see also my blog post about why dir is wrong). fixes #314, fixes #86
This commit is contained in:
@@ -136,7 +136,8 @@ class Script(object):
|
||||
bs = builtin.Builtin.scope
|
||||
completions = get_completions(user_stmt, bs)
|
||||
|
||||
if not dot: # named params have no dots
|
||||
if not dot:
|
||||
# add named params
|
||||
for call_def in self.call_signatures():
|
||||
if not call_def.module.is_builtin():
|
||||
for p in call_def.params:
|
||||
|
||||
@@ -253,9 +253,9 @@ def _generate_code(scope, mixin_funcs={}, depth=0):
|
||||
|
||||
code += get_doc(scope)
|
||||
|
||||
# Remove some magic vars, (TODO why?)
|
||||
names = set(dir(scope)) - set(['__file__', '__name__', '__doc__',
|
||||
'__path__', '__package__']) \
|
||||
| set(['mro'])
|
||||
'__path__', '__package__'])
|
||||
|
||||
classes, funcs, stmts, members = get_scope_objects(names)
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
|
||||
"""
|
||||
names = self._get_self_attributes()
|
||||
|
||||
class_names = self.base.get_defined_names()
|
||||
class_names = self.base.instance_names()
|
||||
for var in class_names:
|
||||
names.append(InstanceElement(self, var, True))
|
||||
return names
|
||||
@@ -164,7 +164,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
|
||||
yield self, self._get_self_attributes()
|
||||
|
||||
names = []
|
||||
class_names = self.base.get_defined_names()
|
||||
class_names = self.base.instance_names()
|
||||
for var in class_names:
|
||||
names.append(InstanceElement(self, var, True))
|
||||
yield self, names
|
||||
@@ -270,7 +270,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
||||
return supers
|
||||
|
||||
@cache.memoize_default(default=())
|
||||
def get_defined_names(self):
|
||||
def instance_names(self):
|
||||
def in_iterable(name, iterable):
|
||||
""" checks if the name is in the variable 'iterable'. """
|
||||
for i in iterable:
|
||||
@@ -285,12 +285,18 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
||||
# TODO mro!
|
||||
for cls in self.get_super_classes():
|
||||
# Get the inherited names.
|
||||
for i in cls.get_defined_names():
|
||||
for i in cls.instance_names():
|
||||
if not in_iterable(i, result):
|
||||
super_result.append(i)
|
||||
result += super_result
|
||||
return result
|
||||
|
||||
@cache.memoize_default(default=())
|
||||
def get_defined_names(self):
|
||||
result = self.instance_names()
|
||||
type_cls = evaluate.find_name(builtin.Builtin.scope, 'type')[0]
|
||||
return result + type_cls.base.get_defined_names()
|
||||
|
||||
def get_subscope_by_name(self, name):
|
||||
for sub in reversed(self.subscopes):
|
||||
if sub.name.get_code() == name:
|
||||
|
||||
@@ -222,8 +222,7 @@ class str():
|
||||
def __init__(self, obj):
|
||||
pass
|
||||
|
||||
class object():
|
||||
|
||||
class type():
|
||||
def mro():
|
||||
""" mro() -> list
|
||||
return a type's method resolution order """
|
||||
return [object]
|
||||
|
||||
@@ -397,3 +397,15 @@ class TestX(object):
|
||||
var = self.conditional_method()
|
||||
#? int()
|
||||
var
|
||||
|
||||
# -----------------
|
||||
# mro method
|
||||
# -----------------
|
||||
|
||||
class A(object):
|
||||
pass
|
||||
|
||||
#? ['mro']
|
||||
A.mro
|
||||
#? []
|
||||
A().mro
|
||||
|
||||
Reference in New Issue
Block a user