mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-06 19:23:59 +08:00
Merge pull request #2097 from davidhalter/py314
Python 3.14; fixes #2093, fixes #2070, will fix #2064 after release.
This commit is contained in:
@@ -7,8 +7,8 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-24.04, windows-2022]
|
||||
python-version: ["3.13", "3.12", "3.11", "3.10"]
|
||||
environment: ['3.13', '3.12', '3.11', '3.10', 'interpreter']
|
||||
python-version: ["3.14", "3.13", "3.12", "3.11", "3.10"]
|
||||
environment: ['3.14', '3.13', '3.12', '3.11', '3.10', 'interpreter']
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -22,7 +22,7 @@ if TYPE_CHECKING:
|
||||
|
||||
_VersionInfo = namedtuple('VersionInfo', 'major minor micro') # type: ignore[name-match]
|
||||
|
||||
_SUPPORTED_PYTHONS = ['3.13', '3.12', '3.11', '3.10']
|
||||
_SUPPORTED_PYTHONS = ['3.14', '3.13', '3.12', '3.11', '3.10']
|
||||
_SAFE_PATHS = ['/usr/bin', '/usr/local/bin']
|
||||
_CONDA_VAR = 'CONDA_PREFIX'
|
||||
_CURRENT_VERSION = '%s.%s' % (sys.version_info.major, sys.version_info.minor)
|
||||
|
||||
@@ -471,18 +471,23 @@ class DirectObjectAccess:
|
||||
op = _OPERATORS[operator]
|
||||
return self._create_access_path(op(self._obj, other_access._obj))
|
||||
|
||||
def get_annotation_name_and_args(self):
|
||||
def get_annotation_name_and_args(self) -> tuple[str | None, tuple[AccessPath, ...]]:
|
||||
"""
|
||||
Returns Tuple[Optional[str], Tuple[AccessPath, ...]]
|
||||
"""
|
||||
name = None
|
||||
args = ()
|
||||
if safe_getattr(self._obj, '__module__', default='') == 'typing':
|
||||
if type(self._obj) is typing.Union: # zuban: ignore[comparison-overlap] # TODO zuban
|
||||
# This is mostly formatted like `int | str` and we therefor need to
|
||||
# check the type.
|
||||
args = typing.get_args(self._obj)
|
||||
name = "Union"
|
||||
elif safe_getattr(self._obj, '__module__', default='') == '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)
|
||||
|
||||
import typing
|
||||
if sys.version_info >= (3, 8):
|
||||
args = typing.get_args(self._obj)
|
||||
else:
|
||||
@@ -493,6 +498,18 @@ class DirectObjectAccess:
|
||||
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 that for consistency
|
||||
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)
|
||||
return ' | '.join(
|
||||
self._annotation_to_str(arg) if hasattr(arg, '__origin__')
|
||||
else getattr(arg, '__name__', str(arg))
|
||||
for arg in args
|
||||
)
|
||||
return inspect.formatannotation(annotation)
|
||||
|
||||
def get_signature_params(self):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -99,6 +99,7 @@ setup(name='jedi',
|
||||
'Programming Language :: Python :: 3.11',
|
||||
'Programming Language :: Python :: 3.12',
|
||||
'Programming Language :: Python :: 3.13',
|
||||
'Programming Language :: Python :: 3.14',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Topic :: Text Editors :: Integrated Development Environments (IDE)',
|
||||
'Topic :: Utilities',
|
||||
|
||||
+1
-4
@@ -104,10 +104,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
import operator
|
||||
if sys.version_info < (3, 8):
|
||||
literal_eval = eval
|
||||
else:
|
||||
from ast import literal_eval
|
||||
from ast import literal_eval
|
||||
from io import StringIO
|
||||
from functools import reduce
|
||||
from unittest.mock import ANY
|
||||
|
||||
@@ -420,7 +420,7 @@ _calls = [
|
||||
(code1, 'f(a,b,xy', 4),
|
||||
(code1, 'f(a,b,xyz=', 4),
|
||||
(code1, 'f(a,b,xy=', None),
|
||||
(code1, 'f(u=', (0, None)),
|
||||
(code1, 'f(u=', None),
|
||||
(code1, 'f(v=', 1),
|
||||
|
||||
# **kwargs
|
||||
@@ -438,7 +438,7 @@ _calls = [
|
||||
(code2, 'g(a,b,abc=1,abd=4,abd=', 5),
|
||||
(code2, 'g(a,b,kw', 5),
|
||||
(code2, 'g(a,b,kwargs=', 5),
|
||||
(code2, 'g(u=', (0, 5)),
|
||||
(code2, 'g(u=', 5),
|
||||
(code2, 'g(v=', 1),
|
||||
|
||||
# *args
|
||||
@@ -450,7 +450,7 @@ _calls = [
|
||||
(code3, 'h(a,b,c,(3,)', 2),
|
||||
(code3, 'h(a,b,args=', None),
|
||||
(code3, 'h(u,v=', 1),
|
||||
(code3, 'h(u=', (0, None)),
|
||||
(code3, 'h(u=', None),
|
||||
(code3, 'h(u,*xxx', 1),
|
||||
(code3, 'h(u,*xxx,*yyy', 1),
|
||||
(code3, 'h(u,*[]', 1),
|
||||
@@ -483,7 +483,7 @@ _calls = [
|
||||
(code4, 'i(1, [a?b,*', 2),
|
||||
(code4, 'i(?b,*r,c', 1),
|
||||
(code4, 'i(?*', 0),
|
||||
(code4, 'i(?**', (0, 1)),
|
||||
(code4, 'i(?**', 1),
|
||||
|
||||
# Random
|
||||
(code4, 'i(()', 0),
|
||||
@@ -497,11 +497,6 @@ _calls = [
|
||||
@pytest.mark.parametrize('ending', ['', ')'])
|
||||
@pytest.mark.parametrize('code, call, expected_index', _calls)
|
||||
def test_signature_index(Script, environment, code, call, expected_index, ending):
|
||||
if isinstance(expected_index, tuple):
|
||||
expected_index = expected_index[environment.version_info > (3, 8)]
|
||||
if environment.version_info < (3, 8):
|
||||
code = code.replace('/,', '')
|
||||
|
||||
sig, = Script(code + '\n' + call + ending).get_signatures(column=len(call))
|
||||
index = sig.index
|
||||
assert expected_index == index
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_find_system_environments():
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'version',
|
||||
['3.10', '3.11', '3.12', '3.13']
|
||||
jedi.api.environment._SUPPORTED_PYTHONS,
|
||||
)
|
||||
def test_versions(version):
|
||||
try:
|
||||
|
||||
@@ -661,17 +661,15 @@ def bar():
|
||||
|
||||
# typing is available via globals.
|
||||
({'return': 'typing.Union[str, int]'}, ['int', 'str'], ''),
|
||||
({'return': 'typing.Union["str", int]'},
|
||||
['int', 'str'] if sys.version_info >= (3, 9) else ['int'], ''),
|
||||
({'return': 'typing.Union["str", int]'}, ['int', 'str'], ''),
|
||||
({'return': 'typing.Union["str", 1]'},
|
||||
['str'] if sys.version_info >= (3, 11) else [], ''),
|
||||
(['str'] if (3, 14) > sys.version_info >= (3, 11) else []), ''),
|
||||
({'return': 'typing.Optional[str]'}, ['NoneType', 'str'], ''),
|
||||
({'return': 'typing.Optional[str, int]'}, [], ''), # Takes only one arg
|
||||
({'return': 'typing.Any'},
|
||||
['_AnyMeta'] if sys.version_info >= (3, 11) else [], ''),
|
||||
|
||||
({'return': 'typing.Tuple[int, str]'},
|
||||
['Tuple' if sys.version_info[:2] == (3, 6) else 'tuple'], ''),
|
||||
({'return': 'typing.Tuple[int, str]'}, ['tuple'], ''),
|
||||
({'return': 'typing.Tuple[int, str]'}, ['int'], 'x()[0]'),
|
||||
({'return': 'typing.Tuple[int, str]'}, ['str'], 'x()[1]'),
|
||||
({'return': 'typing.Tuple[int, str]'}, [], 'x()[2]'),
|
||||
@@ -746,7 +744,8 @@ def test_complete_not_findable_class_source():
|
||||
def test_param_infer_default():
|
||||
abs_sig, = jedi.Interpreter('abs(', [{'abs': abs}]).get_signatures()
|
||||
param, = abs_sig.params
|
||||
assert param.name == 'x'
|
||||
# Parameter name changed from 'x' to 'number' in Python 3.15
|
||||
assert param.name in ('x', 'number')
|
||||
assert param.infer_default() == []
|
||||
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ from test.helpers import root_dir
|
||||
])
|
||||
def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
|
||||
kwargs, type_, options, environment):
|
||||
if type_ == 'infer' and full_name == 'typing.Sequence' and environment.version_info >= (3, 7):
|
||||
# In Python 3.7+ there's not really a sequence definition, there's just
|
||||
if type_ == 'infer' and full_name == 'typing.Sequence':
|
||||
# Since Python 3.7+ there's not really a sequence definition, there's just
|
||||
# a name that leads nowhere.
|
||||
has_python = False
|
||||
|
||||
|
||||
@@ -111,4 +111,4 @@ def test_compiled_signature_annotation_string():
|
||||
|
||||
s, = jedi.Interpreter('func()', [locals()]).get_signatures(1, 5)
|
||||
assert s.params[0].description == 'param x: Type'
|
||||
assert s.params[1].description == 'param y: Union[Type, int]'
|
||||
assert s.params[1].description == 'param y: Type | int'
|
||||
|
||||
@@ -123,10 +123,6 @@ class X:
|
||||
]
|
||||
)
|
||||
def test_tree_signature(Script, environment, code, expected):
|
||||
# Only test this in the latest version, because of /
|
||||
if environment.version_info < (3, 8):
|
||||
pytest.skip()
|
||||
|
||||
if expected is None:
|
||||
assert not Script(code).get_signatures()
|
||||
else:
|
||||
@@ -249,18 +245,11 @@ def test_pow_signature(Script, environment):
|
||||
# See github #1357
|
||||
sigs = Script('pow(').get_signatures()
|
||||
strings = {sig.to_string() for sig in sigs}
|
||||
if environment.version_info < (3, 8):
|
||||
assert strings == {'pow(base: _SupportsPow2[_E, _T_co], exp: _E, /) -> _T_co',
|
||||
'pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M, /) -> _T_co',
|
||||
'pow(base: float, exp: float, mod: None=..., /) -> float',
|
||||
'pow(base: int, exp: int, mod: None=..., /) -> Any',
|
||||
'pow(base: int, exp: int, mod: int, /) -> int'}
|
||||
else:
|
||||
assert strings == {'pow(base: _SupportsPow2[_E, _T_co], exp: _E) -> _T_co',
|
||||
'pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co',
|
||||
'pow(base: float, exp: float, mod: None=...) -> float',
|
||||
'pow(base: int, exp: int, mod: None=...) -> Any',
|
||||
'pow(base: int, exp: int, mod: int) -> int'}
|
||||
assert strings == {'pow(base: _SupportsPow2[_E, _T_co], exp: _E) -> _T_co',
|
||||
'pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co',
|
||||
'pow(base: float, exp: float, mod: None=...) -> float',
|
||||
'pow(base: int, exp: int, mod: None=...) -> Any',
|
||||
'pow(base: int, exp: int, mod: int) -> int'}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -408,13 +397,8 @@ def test_wraps_signature(Script, code, signature):
|
||||
def test_dataclass_signature(
|
||||
Script, start, start_params, include_params, environment
|
||||
):
|
||||
if environment.version_info < (3, 8):
|
||||
# Final is not yet supported
|
||||
price_type = "float"
|
||||
price_type_infer = "float"
|
||||
else:
|
||||
price_type = "Final[float]"
|
||||
price_type_infer = "object"
|
||||
price_type = "Final[float]"
|
||||
price_type_infer = "object"
|
||||
|
||||
code = dedent(
|
||||
f"""
|
||||
@@ -731,13 +715,8 @@ def test_extensions_dataclass_transform_signature(
|
||||
if not has_typing_ext:
|
||||
raise pytest.skip("typing_extensions needed in target environment to run this test")
|
||||
|
||||
if environment.version_info < (3, 8):
|
||||
# Final is not yet supported
|
||||
price_type = "float"
|
||||
price_type_infer = "float"
|
||||
else:
|
||||
price_type = "Final[float]"
|
||||
price_type_infer = "object"
|
||||
price_type = "Final[float]"
|
||||
price_type_infer = "object"
|
||||
|
||||
code = dedent(
|
||||
f"""
|
||||
|
||||
+13
-22
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -53,30 +52,22 @@ def test_completion(case, monkeypatch, environment, has_django):
|
||||
|
||||
# ... and mock the entry points to include it
|
||||
# see https://docs.pytest.org/en/stable/how-to/writing_plugins.html#setuptools-entry-points
|
||||
if sys.version_info >= (3, 8):
|
||||
def mock_entry_points(*, group=None):
|
||||
import importlib.metadata
|
||||
entries = [importlib.metadata.EntryPoint(
|
||||
name=None,
|
||||
value="pytest_plugin.plugin",
|
||||
group="pytest11",
|
||||
)]
|
||||
def mock_entry_points(*, group=None):
|
||||
import importlib.metadata
|
||||
entries = [importlib.metadata.EntryPoint(
|
||||
name=None,
|
||||
value="pytest_plugin.plugin",
|
||||
group="pytest11",
|
||||
)]
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
assert group == "pytest11"
|
||||
return entries
|
||||
else:
|
||||
assert group is None
|
||||
return {"pytest11": entries}
|
||||
|
||||
monkeypatch.setattr("importlib.metadata.entry_points", mock_entry_points)
|
||||
else:
|
||||
def mock_iter_entry_points(group):
|
||||
if sys.version_info >= (3, 10):
|
||||
assert group == "pytest11"
|
||||
EntryPoint = namedtuple("EntryPoint", ["module_name"])
|
||||
return [EntryPoint("pytest_plugin.plugin")]
|
||||
return entries
|
||||
else:
|
||||
assert group is None
|
||||
return {"pytest11": entries}
|
||||
|
||||
monkeypatch.setattr("pkg_resources.iter_entry_points", mock_iter_entry_points)
|
||||
monkeypatch.setattr("importlib.metadata.entry_points", mock_entry_points)
|
||||
|
||||
repo_root = helpers.root_dir
|
||||
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
||||
|
||||
@@ -83,6 +83,9 @@ class TestSetupReadline(unittest.TestCase):
|
||||
'_', 'O_', 'EX_', 'EFD_', 'MFD_', 'TFD_',
|
||||
'SF_', 'ST_', 'CLD_', 'POSIX_SPAWN_', 'P_',
|
||||
'RWF_', 'CLONE_', 'SCHED_', 'SPLICE_',
|
||||
# Python 3.15+ new constants
|
||||
'AT_', 'PIDFD_', 'STATX_', 'GRND_', 'XATTR_',
|
||||
'RTLD_', 'PRIO_', 'F_', 'SEEK_', 'NODEV',
|
||||
]
|
||||
difference = {
|
||||
x for x in difference
|
||||
|
||||
Reference in New Issue
Block a user