mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +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
|
bs = builtin.Builtin.scope
|
||||||
completions = get_completions(user_stmt, bs)
|
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():
|
for call_def in self.call_signatures():
|
||||||
if not call_def.module.is_builtin():
|
if not call_def.module.is_builtin():
|
||||||
for p in call_def.params:
|
for p in call_def.params:
|
||||||
|
|||||||
@@ -253,9 +253,9 @@ def _generate_code(scope, mixin_funcs={}, depth=0):
|
|||||||
|
|
||||||
code += get_doc(scope)
|
code += get_doc(scope)
|
||||||
|
|
||||||
|
# Remove some magic vars, (TODO why?)
|
||||||
names = set(dir(scope)) - set(['__file__', '__name__', '__doc__',
|
names = set(dir(scope)) - set(['__file__', '__name__', '__doc__',
|
||||||
'__path__', '__package__']) \
|
'__path__', '__package__'])
|
||||||
| set(['mro'])
|
|
||||||
|
|
||||||
classes, funcs, stmts, members = get_scope_objects(names)
|
classes, funcs, stmts, members = get_scope_objects(names)
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
|
|||||||
"""
|
"""
|
||||||
names = self._get_self_attributes()
|
names = self._get_self_attributes()
|
||||||
|
|
||||||
class_names = self.base.get_defined_names()
|
class_names = self.base.instance_names()
|
||||||
for var in class_names:
|
for var in class_names:
|
||||||
names.append(InstanceElement(self, var, True))
|
names.append(InstanceElement(self, var, True))
|
||||||
return names
|
return names
|
||||||
@@ -164,7 +164,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
|
|||||||
yield self, self._get_self_attributes()
|
yield self, self._get_self_attributes()
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
class_names = self.base.get_defined_names()
|
class_names = self.base.instance_names()
|
||||||
for var in class_names:
|
for var in class_names:
|
||||||
names.append(InstanceElement(self, var, True))
|
names.append(InstanceElement(self, var, True))
|
||||||
yield self, names
|
yield self, names
|
||||||
@@ -270,7 +270,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
return supers
|
return supers
|
||||||
|
|
||||||
@cache.memoize_default(default=())
|
@cache.memoize_default(default=())
|
||||||
def get_defined_names(self):
|
def instance_names(self):
|
||||||
def in_iterable(name, iterable):
|
def in_iterable(name, iterable):
|
||||||
""" checks if the name is in the variable 'iterable'. """
|
""" checks if the name is in the variable 'iterable'. """
|
||||||
for i in iterable:
|
for i in iterable:
|
||||||
@@ -285,12 +285,18 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
|||||||
# TODO mro!
|
# TODO mro!
|
||||||
for cls in self.get_super_classes():
|
for cls in self.get_super_classes():
|
||||||
# Get the inherited names.
|
# Get the inherited names.
|
||||||
for i in cls.get_defined_names():
|
for i in cls.instance_names():
|
||||||
if not in_iterable(i, result):
|
if not in_iterable(i, result):
|
||||||
super_result.append(i)
|
super_result.append(i)
|
||||||
result += super_result
|
result += super_result
|
||||||
return 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):
|
def get_subscope_by_name(self, name):
|
||||||
for sub in reversed(self.subscopes):
|
for sub in reversed(self.subscopes):
|
||||||
if sub.name.get_code() == name:
|
if sub.name.get_code() == name:
|
||||||
|
|||||||
@@ -222,8 +222,7 @@ class str():
|
|||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class object():
|
|
||||||
|
class type():
|
||||||
def mro():
|
def mro():
|
||||||
""" mro() -> list
|
|
||||||
return a type's method resolution order """
|
|
||||||
return [object]
|
return [object]
|
||||||
|
|||||||
@@ -397,3 +397,15 @@ class TestX(object):
|
|||||||
var = self.conditional_method()
|
var = self.conditional_method()
|
||||||
#? int()
|
#? int()
|
||||||
var
|
var
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# mro method
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class A(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
#? ['mro']
|
||||||
|
A.mro
|
||||||
|
#? []
|
||||||
|
A().mro
|
||||||
|
|||||||
Reference in New Issue
Block a user