mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 15:51:51 +08:00
get_annotation -> annotation (property).
This commit is contained in:
@@ -81,18 +81,18 @@ def _fix_forward_reference(context, node):
|
|||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def follow_param(context, param):
|
def follow_param(context, param):
|
||||||
annotation = param.get_annotation()
|
annotation = param.annotation
|
||||||
return _evaluate_for_annotation(context, annotation)
|
return _evaluate_for_annotation(context, annotation)
|
||||||
|
|
||||||
|
|
||||||
def py__annotations__(funcdef):
|
def py__annotations__(funcdef):
|
||||||
return_annotation = funcdef.get_annotation()
|
return_annotation = funcdef.annotation
|
||||||
if return_annotation:
|
if return_annotation:
|
||||||
dct = {'return': return_annotation}
|
dct = {'return': return_annotation}
|
||||||
else:
|
else:
|
||||||
dct = {}
|
dct = {}
|
||||||
for function_param in funcdef.params:
|
for function_param in funcdef.params:
|
||||||
param_annotation = function_param.get_annotation()
|
param_annotation = function_param.annotation
|
||||||
if param_annotation is not None:
|
if param_annotation is not None:
|
||||||
dct[function_param.name.value] = param_annotation
|
dct[function_param.name.value] = param_annotation
|
||||||
return dct
|
return dct
|
||||||
|
|||||||
@@ -588,7 +588,8 @@ class Function(ClassOrFunc):
|
|||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return bool(self.yields)
|
return bool(self.yields)
|
||||||
|
|
||||||
def get_annotation(self):
|
@property
|
||||||
|
def annotation(self):
|
||||||
try:
|
try:
|
||||||
if self.children[3] == "->":
|
if self.children[3] == "->":
|
||||||
return self.children[4]
|
return self.children[4]
|
||||||
@@ -656,7 +657,8 @@ class Lambda(Function):
|
|||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_annotation(self):
|
@property
|
||||||
|
def annotation(self):
|
||||||
# lambda functions do not support annotations
|
# lambda functions do not support annotations
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1066,7 +1068,8 @@ class Param(PythonBaseNode):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_annotation(self):
|
@property
|
||||||
|
def annotation(self):
|
||||||
tfpdef = self._tfpdef()
|
tfpdef = self._tfpdef()
|
||||||
if tfpdef.type == 'tfpdef':
|
if tfpdef.type == 'tfpdef':
|
||||||
assert tfpdef.children[1] == ":"
|
assert tfpdef.children[1] == ":"
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ class TestsFunctionAndLambdaParsing(object):
|
|||||||
def test_annotation(self, node, expected):
|
def test_annotation(self, node, expected):
|
||||||
expected_annotation = expected.get('annotation', None)
|
expected_annotation = expected.get('annotation', None)
|
||||||
if expected_annotation is None:
|
if expected_annotation is None:
|
||||||
assert node.get_annotation() is None
|
assert node.annotation is None
|
||||||
else:
|
else:
|
||||||
assert node.get_annotation().value == expected_annotation
|
assert node.annotation.value == expected_annotation
|
||||||
|
|
||||||
def test_get_call_signature(self, node, expected):
|
def test_get_call_signature(self, node, expected):
|
||||||
assert node.get_call_signature() == expected['call_sig']
|
assert node.get_call_signature() == expected['call_sig']
|
||||||
|
|||||||
Reference in New Issue
Block a user