Skip to content

Commit 93064fe

Browse files
Pierre-Sassoulascdce8p
authored andcommitted
Remove syntax error from shared code
1 parent 67a7691 commit 93064fe

File tree

3 files changed

+109
-5
lines changed

3 files changed

+109
-5
lines changed

tests/test_nodes.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
transforms,
2929
util,
3030
)
31-
from astroid.const import IS_PYPY, PY310_PLUS, PY312_PLUS, Context
31+
from astroid.const import IS_PYPY, PY310_PLUS, PY312_PLUS, PY314_PLUS, Context
3232
from astroid.context import InferenceContext
3333
from astroid.exceptions import (
3434
AstroidBuildingError,
@@ -115,12 +115,23 @@ def test_varargs_kwargs_as_string(self) -> None:
115115
ast = abuilder.string_build("raise_string(*args, **kwargs)").body[0]
116116
self.assertEqual(ast.as_string(), "raise_string(*args, **kwargs)")
117117

118-
def test_module_as_string(self) -> None:
119-
"""Check as_string on a whole module prepared to be returned identically."""
118+
@pytest.mark.skipif(PY314_PLUS, reason="return in finally is now a syntax error")
119+
def test_module_as_string_pre_3_14(self) -> None:
120+
"""Check as_string on a whole module prepared to be returned identically for py < 3.14."""
121+
self.maxDiff = None
120122
module = resources.build_file("data/module.py", "data.module")
121123
with open(resources.find("data/module.py"), encoding="utf-8") as fobj:
122124
self.assertMultiLineEqual(module.as_string(), fobj.read())
123125

126+
@pytest.mark.skipif(
127+
not PY314_PLUS, reason="return in finally is now a syntax error"
128+
)
129+
def test_module_as_string(self) -> None:
130+
"""Check as_string on a whole module prepared to be returned identically for py > 3.14."""
131+
module = resources.build_file("data/module3.14.py", "data.module3.14")
132+
with open(resources.find("data/module3.14.py"), encoding="utf-8") as fobj:
133+
self.assertMultiLineEqual(module.as_string(), fobj.read())
134+
124135
def test_module2_as_string(self) -> None:
125136
"""Check as_string on a whole module prepared to be returned identically."""
126137
module2 = resources.build_file("data/module2.py", "data.module2")

tests/testdata/python3/data/module.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def method(self):
5959
return 'hehe'
6060
global_access(local, val=autre)
6161
finally:
62-
return local
63-
62+
# return in finally was previousely tested here but became a syntax error
63+
# in 3.14 and this file is used in 188/1464 tests
64+
a = local
65+
6466
def static_method():
6567
"""static method test"""
6668
assert MY_DICT, '???'
+91
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 previousely 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)