mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 09:18:36 +08:00
Fix descriptors.
This commit is contained in:
+16
-10
@@ -65,7 +65,7 @@ class NameFinder(object):
|
|||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
def find(self, scopes, search_global=False):
|
def find(self, scopes, search_global=False):
|
||||||
names = self.filter_name(scopes, search_global)
|
names = self.filter_name(scopes, search_global)
|
||||||
types = self._names_to_types(names)
|
types = self._names_to_types(names, search_global)
|
||||||
|
|
||||||
if not names and not types \
|
if not names and not types \
|
||||||
and not (isinstance(self.name_str, pr.Name)
|
and not (isinstance(self.name_str, pr.Name)
|
||||||
@@ -81,10 +81,7 @@ class NameFinder(object):
|
|||||||
self.scope, self.name_str)
|
self.scope, self.name_str)
|
||||||
|
|
||||||
debug.dbg('finder._names_to_types: %s -> %s', names, types)
|
debug.dbg('finder._names_to_types: %s -> %s', names, types)
|
||||||
if isinstance(self.scope, (er.Class, er.Instance)) and not search_global:
|
return types
|
||||||
return self._resolve_descriptors(types)
|
|
||||||
else:
|
|
||||||
return types
|
|
||||||
|
|
||||||
def scopes(self, search_global=False):
|
def scopes(self, search_global=False):
|
||||||
if search_global:
|
if search_global:
|
||||||
@@ -307,7 +304,7 @@ class NameFinder(object):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _names_to_types(self, names):
|
def _names_to_types(self, names, search_global):
|
||||||
types = []
|
types = []
|
||||||
|
|
||||||
# Add isinstance and other if/assert knowledge.
|
# Add isinstance and other if/assert knowledge.
|
||||||
@@ -324,17 +321,26 @@ class NameFinder(object):
|
|||||||
flow_scope = flow_scope.parent
|
flow_scope = flow_scope.parent
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
types += _name_to_types(self._evaluator, name, self.scope)
|
new_types = _name_to_types(self._evaluator, name, self.scope)
|
||||||
|
if isinstance(self.scope, (er.Class, er.Instance)) and not search_global:
|
||||||
|
types += self._resolve_descriptors(name, new_types)
|
||||||
|
else:
|
||||||
|
types += new_types
|
||||||
if not names and isinstance(self.scope, er.Instance):
|
if not names and isinstance(self.scope, er.Instance):
|
||||||
# handling __getattr__ / __getattribute__
|
# handling __getattr__ / __getattribute__
|
||||||
types = self._check_getattr(self.scope)
|
types = self._check_getattr(self.scope)
|
||||||
|
|
||||||
return types
|
return types
|
||||||
|
|
||||||
def _resolve_descriptors(self, types):
|
def _resolve_descriptors(self, name, types):
|
||||||
"""Processes descriptors"""
|
"""Processes descriptors"""
|
||||||
#if not self.maybe_descriptor:
|
# The name must not be in the dictionary, but part of the class
|
||||||
# return types
|
# definition. __get__ is only called if the descriptor is defined in
|
||||||
|
# the class dictionary.
|
||||||
|
name_scope = name.get_definition().get_parent_scope()
|
||||||
|
if not isinstance(name_scope, (er.Instance, pr.Class)):
|
||||||
|
return types
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for r in types:
|
for r in types:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user