mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix an issue with api_name of class attributes, fixes #1688
This commit is contained in:
@@ -75,9 +75,9 @@ class ClassName(TreeNameDefinition):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def api_type(self):
|
def api_type(self):
|
||||||
if self.tree_name is not None:
|
type_ = super().api_type
|
||||||
|
if type_ == 'function':
|
||||||
definition = self.tree_name.get_definition()
|
definition = self.tree_name.get_definition()
|
||||||
if definition.type == 'funcdef':
|
|
||||||
if function_is_property(definition):
|
if function_is_property(definition):
|
||||||
# This essentially checks if there is an @property before
|
# This essentially checks if there is an @property before
|
||||||
# the function. @property could be something different, but
|
# the function. @property could be something different, but
|
||||||
@@ -85,7 +85,7 @@ class ClassName(TreeNameDefinition):
|
|||||||
# is not really a property anymore, should be shot. (i.e.
|
# is not really a property anymore, should be shot. (i.e.
|
||||||
# this is a heuristic).
|
# this is a heuristic).
|
||||||
return 'property'
|
return 'property'
|
||||||
return super().api_type
|
return type_
|
||||||
|
|
||||||
|
|
||||||
class ClassFilter(ParserTreeFilter):
|
class ClassFilter(ParserTreeFilter):
|
||||||
|
|||||||
@@ -214,6 +214,20 @@ f
|
|||||||
#? str()
|
#? str()
|
||||||
g
|
g
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# setitem
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class F:
|
||||||
|
setitem_x = [1,2]
|
||||||
|
setitem_x[0] = 3
|
||||||
|
|
||||||
|
#? ['setitem_x']
|
||||||
|
F().setitem_x
|
||||||
|
#? list()
|
||||||
|
F().setitem_x
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# dicts
|
# dicts
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
@@ -209,6 +209,9 @@ class IntegrationTestCase(BaseTestCase):
|
|||||||
# import cProfile; cProfile.run('...')
|
# import cProfile; cProfile.run('...')
|
||||||
|
|
||||||
comp_str = {c.name for c in completions}
|
comp_str = {c.name for c in completions}
|
||||||
|
for r in completions:
|
||||||
|
# Test if this access raises an error
|
||||||
|
assert isinstance(r.type, str)
|
||||||
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
return compare_cb(self, comp_str, set(literal_eval(self.correct)))
|
||||||
|
|
||||||
def run_inference(self, compare_cb, environment):
|
def run_inference(self, compare_cb, environment):
|
||||||
@@ -244,6 +247,9 @@ class IntegrationTestCase(BaseTestCase):
|
|||||||
should = definition(self.correct, self.start, script.path)
|
should = definition(self.correct, self.start, script.path)
|
||||||
result = script.infer(self.line_nr, self.column)
|
result = script.infer(self.line_nr, self.column)
|
||||||
is_str = set(comparison(r) for r in result)
|
is_str = set(comparison(r) for r in result)
|
||||||
|
for r in result:
|
||||||
|
# Test if this access raises an error
|
||||||
|
assert isinstance(r.type, str)
|
||||||
return compare_cb(self, is_str, should)
|
return compare_cb(self, is_str, should)
|
||||||
|
|
||||||
def run_goto(self, compare_cb, environment):
|
def run_goto(self, compare_cb, environment):
|
||||||
|
|||||||
Reference in New Issue
Block a user