1
0
forked from VimPlug/jedi

Merge branch 'py314' of https://github.com/frenzymadness/jedi into py314

This commit is contained in:
Dave Halter
2026-04-27 12:22:31 +02:00
4 changed files with 43 additions and 9 deletions
+33 -6
View File
@@ -477,22 +477,49 @@ class DirectObjectAccess:
"""
name = None
args = ()
if safe_getattr(self._obj, '__module__', default='') == 'typing':
# Use getattr instead of safe_getattr for __module__ as getattr_static
# fails on typing types in Python 3.14+
module = getattr(self._obj, '__module__', '')
if module == 'typing':
import typing
# Try regex first (works for most types)
m = re.match(r'typing.(\w+)\[', repr(self._obj))
if m is not None:
name = m.group(1)
elif sys.version_info >= (3, 8):
# Fallback to get_origin() for Python 3.8+ when regex fails
# In Python 3.14+, Union/Optional repr changed to use | syntax
origin = typing.get_origin(self._obj)
if origin is typing.Union:
name = 'Union'
import typing
if sys.version_info >= (3, 8):
args = typing.get_args(self._obj)
else:
args = safe_getattr(self._obj, '__args__', default=None)
# Get args
if sys.version_info >= (3, 8):
args = typing.get_args(self._obj)
else:
args = safe_getattr(self._obj, '__args__', default=None)
if args is None:
args = ()
return name, tuple(self._create_access_path(arg) for arg in args)
def needs_type_completions(self):
return inspect.isclass(self._obj) and self._obj != type
def _annotation_to_str(self, annotation):
# In Python 3.14+, Union types are displayed as X | Y instead of Union[X, Y]
# We normalize to Union[X, Y] for consistency
if sys.version_info >= (3, 8):
import typing
origin = typing.get_origin(annotation)
if origin is typing.Union:
# Get the args and format them as Union[...]
args = typing.get_args(annotation)
formatted_args = ', '.join(
self._annotation_to_str(arg) if hasattr(arg, '__origin__')
else getattr(arg, '__name__', str(arg))
for arg in args
)
return f'Union[{formatted_args}]'
return inspect.formatannotation(annotation)
def get_signature_params(self):
+4 -1
View File
@@ -90,7 +90,10 @@ def getattr_static(obj, attr, default=_sentinel):
if not _is_type(obj):
klass = type(obj)
dict_attr = _shadowed_dict(klass)
if (dict_attr is _sentinel or type(dict_attr) is types.MemberDescriptorType):
# In Python 3.15+, __dict__ is a GetSetDescriptorType instead of being _sentinel
if (dict_attr is _sentinel
or type(dict_attr) is types.MemberDescriptorType
or type(dict_attr) is types.GetSetDescriptorType):
instance_result = _check_instance(obj, attr)
else:
klass = obj