Skip to content

Commit c94e0b7

Browse files
[ci] Start testing on python 3.14-beta (#2731)
* [ci] Start testing on python 3.14-beta * Remove syntax error from shared code * Fix failing tests --------- Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
1 parent e0a7642 commit c94e0b7

File tree

5 files changed

+128
-8
lines changed

5 files changed

+128
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
strategy:
8282
fail-fast: false
8383
matrix:
84-
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
84+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
8585
outputs:
8686
python-key: ${{ steps.generate-python-key.outputs.key }}
8787
steps:
@@ -139,7 +139,7 @@ jobs:
139139
strategy:
140140
fail-fast: false
141141
matrix:
142-
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
142+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
143143
steps:
144144
- name: Set temp directory
145145
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV

tests/test_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def test_method_locals(self) -> None:
850850
"""Test the 'locals' dictionary of an astroid method."""
851851
method = self.module["YOUPI"]["method"]
852852
# ListComp variables are not accessible outside
853-
self.assertEqual(sorted(method.locals), ["autre", "local", "self"])
853+
self.assertEqual(sorted(method.locals), ["a", "autre", "local", "self"])
854854

855855
def test_unknown_encoding(self) -> None:
856856
with self.assertRaises(AstroidSyntaxError):

tests/test_nodes.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
transforms,
2929
util,
3030
)
31-
from astroid.const import IS_PYPY, PY310_PLUS, PY311_PLUS, PY312_PLUS, Context
31+
from astroid.const import (
32+
IS_PYPY,
33+
PY310_PLUS,
34+
PY311_PLUS,
35+
PY312_PLUS,
36+
PY314_PLUS,
37+
Context,
38+
)
3239
from astroid.context import InferenceContext
3340
from astroid.exceptions import (
3441
AstroidBuildingError,
@@ -115,11 +122,31 @@ def test_varargs_kwargs_as_string(self) -> None:
115122
ast = abuilder.string_build("raise_string(*args, **kwargs)").body[0]
116123
self.assertEqual(ast.as_string(), "raise_string(*args, **kwargs)")
117124

118-
def test_module_as_string(self) -> None:
119-
"""Check as_string on a whole module prepared to be returned identically."""
125+
@pytest.mark.skipif(PY314_PLUS, reason="return in finally is now a syntax error")
126+
def test_module_as_string_pre_3_14(self) -> None:
127+
"""Check as_string on a whole module prepared to be returned identically for py < 3.14."""
128+
self.maxDiff = None
120129
module = resources.build_file("data/module.py", "data.module")
121130
with open(resources.find("data/module.py"), encoding="utf-8") as fobj:
122-
self.assertMultiLineEqual(module.as_string(), fobj.read())
131+
# Ignore comments in python file
132+
data_str = "\n".join(
133+
[s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")]
134+
)
135+
self.assertMultiLineEqual(module.as_string(), data_str)
136+
137+
@pytest.mark.skipif(
138+
not PY314_PLUS, reason="return in finally is now a syntax error"
139+
)
140+
def test_module_as_string(self) -> None:
141+
"""Check as_string on a whole module prepared to be returned identically for py > 3.14."""
142+
self.maxDiff = None
143+
module = resources.build_file("data/module3.14.py", "data.module3.14")
144+
with open(resources.find("data/module3.14.py"), encoding="utf-8") as fobj:
145+
# Ignore comments in python file
146+
data_str = "\n".join(
147+
[s for s in fobj.read().split("\n") if not s.lstrip().startswith("# ")]
148+
)
149+
self.assertMultiLineEqual(module.as_string(), data_str)
123150

124151
def test_module2_as_string(self) -> None:
125152
"""Check as_string on a whole module prepared to be returned identically."""

tests/testdata/python3/data/module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def method(self):
5959
return 'hehe'
6060
global_access(local, val=autre)
6161
finally:
62-
return local
62+
# return in finally was previously tested here but became a syntax error
63+
# in 3.14 and this file is used in 188/1464 tests
64+
a = local
6365

6466
def static_method():
6567
"""static method test"""
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""test module for astroid
2+
"""
3+
4+
__revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $'
5+
from astroid.nodes.node_classes import Name as NameNode
6+
from astroid import modutils
7+
from astroid.utils import *
8+
import os.path
9+
MY_DICT = {}
10+
11+
def global_access(key, val):
12+
"""function test"""
13+
local = 1
14+
MY_DICT[key] = val
15+
for i in val:
16+
if i:
17+
del MY_DICT[i]
18+
continue
19+
else:
20+
break
21+
else:
22+
return
23+
24+
25+
class YO:
26+
"""hehe
27+
haha"""
28+
a = 1
29+
30+
def __init__(self):
31+
try:
32+
self.yo = 1
33+
except ValueError as ex:
34+
pass
35+
except (NameError, TypeError):
36+
raise XXXError()
37+
except:
38+
raise
39+
40+
41+
42+
class YOUPI(YO):
43+
class_attr = None
44+
45+
def __init__(self):
46+
self.member = None
47+
48+
def method(self):
49+
"""method
50+
test"""
51+
global MY_DICT
52+
try:
53+
MY_DICT = {}
54+
local = None
55+
autre = [a for (a, b) in MY_DICT if b]
56+
if b in autre:
57+
return
58+
elif a in autre:
59+
return 'hehe'
60+
global_access(local, val=autre)
61+
finally:
62+
# return in finally was previously tested here but became a syntax error
63+
# in 3.14 and is used in 188/1464 tests
64+
print(local)
65+
66+
def static_method():
67+
"""static method test"""
68+
assert MY_DICT, '???'
69+
static_method = staticmethod(static_method)
70+
71+
def class_method(cls):
72+
"""class method test"""
73+
exec(a, b)
74+
class_method = classmethod(class_method)
75+
76+
77+
def four_args(a, b, c, d):
78+
"""four arguments (was nested_args)"""
79+
while 1:
80+
if a:
81+
break
82+
a += +1
83+
else:
84+
b += -2
85+
if c:
86+
d = a and (b or c)
87+
else:
88+
c = a and b or d
89+
list(map(lambda x, y: (y, x), a))
90+
redirect = four_args
91+

0 commit comments

Comments
 (0)