mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Refactor the ClassName to allow inheritance in different modules. Fixes #884.
This commit is contained in:
@@ -75,8 +75,19 @@ def apply_py__get__(context, base_context):
|
|||||||
|
|
||||||
|
|
||||||
class ClassName(TreeNameDefinition):
|
class ClassName(TreeNameDefinition):
|
||||||
|
def __init__(self, parent_context, tree_name, name_context):
|
||||||
|
super(ClassName, self).__init__(parent_context, tree_name)
|
||||||
|
self._name_context = name_context
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
for result_context in super(ClassName, self).infer():
|
# TODO this _name_to_types might get refactored and be a part of the
|
||||||
|
# parent class. Once it is, we can probably just overwrite method to
|
||||||
|
# achieve this.
|
||||||
|
from jedi.evaluate.finder import _name_to_types
|
||||||
|
inferred = _name_to_types(
|
||||||
|
self.parent_context.evaluator, self._name_context, self.tree_name)
|
||||||
|
|
||||||
|
for result_context in inferred:
|
||||||
for c in apply_py__get__(result_context, self.parent_context):
|
for c in apply_py__get__(result_context, self.parent_context):
|
||||||
yield c
|
yield c
|
||||||
|
|
||||||
@@ -84,6 +95,10 @@ class ClassName(TreeNameDefinition):
|
|||||||
class ClassFilter(ParserTreeFilter):
|
class ClassFilter(ParserTreeFilter):
|
||||||
name_class = ClassName
|
name_class = ClassName
|
||||||
|
|
||||||
|
def _convert_names(self, names):
|
||||||
|
return [self.name_class(self.context, name, self._node_context)
|
||||||
|
for name in names]
|
||||||
|
|
||||||
|
|
||||||
class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||||
"""
|
"""
|
||||||
@@ -162,13 +177,13 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
|||||||
origin_scope=origin_scope
|
origin_scope=origin_scope
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
for scope in self.py__mro__():
|
for cls in self.py__mro__():
|
||||||
if isinstance(scope, compiled.CompiledObject):
|
if isinstance(cls, compiled.CompiledObject):
|
||||||
for filter in scope.get_filters(is_instance=is_instance):
|
for filter in cls.get_filters(is_instance=is_instance):
|
||||||
yield filter
|
yield filter
|
||||||
else:
|
else:
|
||||||
yield ClassFilter(
|
yield ClassFilter(
|
||||||
self.evaluator, self, node_context=scope,
|
self.evaluator, self, node_context=cls,
|
||||||
origin_scope=origin_scope)
|
origin_scope=origin_scope)
|
||||||
|
|
||||||
def is_class(self):
|
def is_class(self):
|
||||||
|
|||||||
@@ -493,3 +493,19 @@ B().a
|
|||||||
B.b
|
B.b
|
||||||
#? int()
|
#? int()
|
||||||
B().b
|
B().b
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# With import
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
from import_tree.classes import Config2, BaseClass
|
||||||
|
|
||||||
|
class Config(BaseClass):
|
||||||
|
"""#884"""
|
||||||
|
|
||||||
|
#? Config2()
|
||||||
|
Config.mode
|
||||||
|
|
||||||
|
#? int()
|
||||||
|
Config.mode2
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ from import_tree.pkg.mod1 import not_existant, # whitespace before
|
|||||||
from import_tree.pkg.mod1 import not_existant,
|
from import_tree.pkg.mod1 import not_existant,
|
||||||
#? 22 ['mod1']
|
#? 22 ['mod1']
|
||||||
from import_tree.pkg. import mod1
|
from import_tree.pkg. import mod1
|
||||||
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'recurse_class1', 'recurse_class2', 'invisible_pkg', 'flow_import']
|
#? 17 ['mod1', 'mod2', 'random', 'pkg', 'rename1', 'rename2', 'classes', 'recurse_class1', 'recurse_class2', 'invisible_pkg', 'flow_import']
|
||||||
from import_tree. import pkg
|
from import_tree. import pkg
|
||||||
|
|
||||||
#? 18 ['pkg']
|
#? 18 ['pkg']
|
||||||
|
|||||||
Reference in New Issue
Block a user