Skip to content

Commit

Permalink
Merge branch 'python-3.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJCLaw committed Jul 6, 2024
2 parents e839683 + 857c9be commit 82d1902
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, windows-2019]
python-version: ["3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"]
environment: ['3.8', '3.12', '3.11', '3.10', '3.9', '3.7', '3.6', 'interpreter']
python-version: ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"]
environment: ['3.8', '3.13', '3.12', '3.11', '3.10', '3.9', '3.7', '3.6', 'interpreter']
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog
Unreleased
++++++++++

- Python 3.13 support

0.19.1 (2023-10-02)
+++++++++++++++++++

Expand Down
15 changes: 14 additions & 1 deletion jedi/_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
import errno
import sys
import pickle
from typing import Any


class Unpickler(pickle.Unpickler):
def find_class(self, module: str, name: str) -> Any:
# Python 3.13 moved pathlib implementation out of __init__.py as part of
# generalising its implementation. Ensure that we support loading
# pickles from 3.13 on older version of Python. Since 3.13 maintained a
# compatible API, pickles from older Python work natively on the newer
# version.
if module == 'pathlib._local':
module = 'pathlib'
return super().find_class(module, name)


def pickle_load(file):
try:
return pickle.load(file)
return Unpickler(file).load()
# Python on Windows don't throw EOF errors for pipes. So reraise them with
# the correct type, which is caught upwards.
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion jedi/api/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

_VersionInfo = namedtuple('VersionInfo', 'major minor micro') # type: ignore[name-match]

_SUPPORTED_PYTHONS = ['3.12', '3.11', '3.10', '3.9', '3.8', '3.7', '3.6']
_SUPPORTED_PYTHONS = ['3.13', '3.12', '3.11', '3.10', '3.9', '3.8', '3.7', '3.6']
_SAFE_PATHS = ['/usr/bin', '/usr/local/bin']
_CONDA_VAR = 'CONDA_PREFIX'
_CURRENT_VERSION = '%s.%s' % (sys.version_info.major, sys.version_info.minor)
Expand Down
2 changes: 1 addition & 1 deletion jedi/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, project, environment=None, script_path=None):
self.compiled_subprocess = environment.get_inference_state_subprocess(self)
self.grammar = environment.get_grammar()

self.latest_grammar = parso.load_grammar(version='3.12')
self.latest_grammar = parso.load_grammar(version='3.13')
self.memoize_cache = {} # for memoize decorators
self.module_cache = imports.ModuleCache() # does the job of `sys.modules`.
self.stub_module_cache = {} # Dict[Tuple[str, ...], Optional[ModuleValue]]
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
long_description=readme,
packages=find_packages(exclude=['test', 'test.*']),
python_requires='>=3.6',
# Python 3.11 & 3.12 grammars are added to parso in 0.8.3
install_requires=['parso>=0.8.3,<0.9.0'],
# Python 3.13 grammars are added to parso in 0.8.4
install_requires=['parso>=0.8.4,<0.9.0'],
extras_require={
'testing': [
'pytest<9.0.0',
Expand Down Expand Up @@ -101,6 +101,7 @@
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Editors :: Integrated Development Environments (IDE)',
'Topic :: Utilities',
Expand Down
13 changes: 9 additions & 4 deletions test/test_api/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ def test_completion_param_annotations():
# Need to define this function not directly in Python. Otherwise Jedi is too
# clever and uses the Python code instead of the signature object.
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
exec(code, locals())
script = jedi.Interpreter('foo', [locals()])
exec_locals = {}
exec(code, exec_locals)
script = jedi.Interpreter('foo', [exec_locals])
c, = script.complete()
sig, = c.get_signatures()
a, b, c = sig.params
Expand All @@ -323,7 +324,7 @@ def test_completion_param_annotations():
assert b.description == 'param b: str'
assert c.description == 'param c: int=1.0'

d, = jedi.Interpreter('foo()', [locals()]).infer()
d, = jedi.Interpreter('foo()', [exec_locals]).infer()
assert d.name == 'bytes'


Expand Down Expand Up @@ -525,10 +526,14 @@ def func(a, b, c):
c = functools.partial(func, 1, c=2)

sig, = jedi.Interpreter(code, [locals()]).get_signatures()
assert sig.name == 'partial'
assert [p.name for p in sig.params] == expected
assert index == sig.index

if sys.version_info < (3, 13):
# Python 3.13.0b3 makes functools.partial be a descriptor, which breaks
# Jedi's `py__name__` detection; see https://github.com/davidhalter/jedi/issues/2012
assert sig.name == 'partial'


def test_type_var():
"""This was an issue before, see Github #1369"""
Expand Down
5 changes: 3 additions & 2 deletions test/test_inference/test_signature.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from textwrap import dedent
from operator import ge, lt
from operator import eq, ge, lt
import re
import os

Expand All @@ -14,7 +14,8 @@
('import math; math.cos', 'cos(x, /)', ['x'], ge, (3, 6)),
('next', 'next(iterator, default=None, /)', ['iterator', 'default'], lt, (3, 12)),
('next', 'next()', [], ge, (3, 12)),
('next', 'next()', [], eq, (3, 12)),
('next', 'next(iterator, default=None, /)', ['iterator', 'default'], ge, (3, 13)),
('str', "str(object='', /) -> str", ['object'], ge, (3, 6)),
Expand Down
14 changes: 10 additions & 4 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,21 @@ def test_import(self):
import os
s = 'from os import '
goal = {s + el for el in dir(os)}

# There are minor differences, e.g. the dir doesn't include deleted
# items as well as items that are not only available on linux.
difference = set(self.complete(s)).symmetric_difference(goal)
ACCEPTED_DIFFERENCE_PREFIXES = [
'_', 'O_', 'EX_', 'EFD_', 'MFD_', 'TFD_',
'SF_', 'ST_', 'CLD_', 'POSIX_SPAWN_', 'P_',
'RWF_', 'CLONE_', 'SCHED_', 'SPLICE_',
]
difference = {
x for x in difference
if all(not x.startswith('from os import ' + s)
for s in ['_', 'O_', 'EX_', 'MFD_', 'SF_', 'ST_',
'CLD_', 'POSIX_SPAWN_', 'P_', 'RWF_',
'CLONE_', 'SCHED_'])
if not any(
x.startswith('from os import ' + prefix)
for prefix in ACCEPTED_DIFFERENCE_PREFIXES
)
}
# There are quite a few differences, because both Windows and Linux
# (posix and nt) libraries are included.
Expand Down

0 comments on commit 82d1902

Please sign in to comment.