1
0
forked from VimPlug/jedi

Try to use the return annotations of properties, if available, fixes #1933

This commit is contained in:
Dave Halter
2023-07-28 22:35:07 +02:00
parent ff3a7f367f
commit 886279fb6d
3 changed files with 60 additions and 2 deletions

View File

@@ -354,7 +354,7 @@ class DirectObjectAccess:
if is_get_descriptor and type(attr) not in ALLOWED_DESCRIPTOR_ACCESS:
if isinstance(attr, property):
if hasattr(attr.fget, '__annotations__'):
a = DirectObjectAccess(self._inference_state, attr)
a = DirectObjectAccess(self._inference_state, attr.fget)
return True, True, a.get_return_annotation()
# In case of descriptors that have get methods we cannot return
# it's value, because that would mean code execution.

View File

@@ -51,7 +51,6 @@ class CompiledValue(Value):
def py__call__(self, arguments):
return_annotation = self.access_handle.get_return_annotation()
if return_annotation is not None:
# TODO the return annotation may also be a string.
return create_from_access_path(
self.inference_state,
return_annotation
@@ -453,6 +452,14 @@ class CompiledValueFilter(AbstractFilter):
has_attribute, is_descriptor, property_return_annotation = allowed_getattr_callback(
name,
)
if property_return_annotation is not None:
values = create_from_access_path(
self._inference_state,
property_return_annotation
).execute_annotation()
if values:
return [CompiledValueName(v, name) for v in values]
if check_has_attribute and not has_attribute:
return []