Skip to content

Commit 7312cbd

Browse files
authored
Merge pull request #1152 from PyCQA/py312
get testsuite passing on 3.12
2 parents 54b053e + e8d8409 commit 7312cbd

File tree

8 files changed

+93
-54
lines changed

8 files changed

+93
-54
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
py: 3.9
1515
toxenv: py
1616
- os: ubuntu-latest
17-
py: pypy3.9
17+
py: pypy3.10
1818
toxenv: py
1919
- os: ubuntu-latest
2020
py: 3.7
@@ -31,6 +31,9 @@ jobs:
3131
- os: ubuntu-latest
3232
py: '3.11'
3333
toxenv: py
34+
- os: ubuntu-latest
35+
py: '3.12-dev'
36+
toxenv: py
3437
- os: ubuntu-latest
3538
py: 3.9
3639
toxenv: flake8
@@ -40,5 +43,10 @@ jobs:
4043
- uses: actions/setup-python@v4
4144
with:
4245
python-version: ${{ matrix.py }}
46+
if: matrix.py != '3.12-dev'
47+
- uses: deadsnakes/[email protected]
48+
with:
49+
python-version: ${{ matrix.py }}
50+
if: matrix.py == '3.12-dev'
4351
- run: pip install tox
4452
- run: tox -e ${{ matrix.toxenv }}

pycodestyle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ def tabs_or_spaces(physical_line, indent_char):
196196
These options are highly recommended!
197197
198198
Okay: if a == 0:\n a = 1\n b = 1
199-
E101: if a == 0:\n a = 1\n\tb = 1
200199
"""
201200
indent = INDENT_REGEX.match(physical_line).group(1)
202201
for offset, char in enumerate(indent):
@@ -802,9 +801,10 @@ def whitespace_before_parameters(logical_line, tokens):
802801
(index < 2 or tokens[index - 2][1] != 'class') and
803802
# Allow "return (a.foo for a in range(5))"
804803
not keyword.iskeyword(prev_text) and
805-
# 'match' and 'case' are only soft keywords
806804
(
807805
sys.version_info < (3, 9) or
806+
# 3.12+: type is a soft keyword but no braces after
807+
prev_text == 'type' or
808808
not keyword.issoftkeyword(prev_text)
809809
)
810810
):

testsuite/E10.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#: E101 W191
2-
for a in 'abc':
3-
for b in 'xyz':
4-
print a # indented with 8 spaces
5-
print b # indented with 1 tab
61
#: E101 E122 W191 W191
72
if True:
83
pass

testsuite/E90.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
#: E901
2-
}
3-
#: E901
42
= [x
53
#: E901 E101 W191
64
while True:
75
try:
86
pass
97
except:
108
print 'Whoops'
11-
#: E122 E225 E251 E251
12-
13-
# Do not crash if code is invalid
14-
if msg:
15-
errmsg = msg % progress.get(cr_dbname))
16-
17-
def lasting(self, duration=300):
18-
progress = self._progress.setdefault('foo', {}
199
#: Okay
2010

2111
# Issue #119

testsuite/python312.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#: Okay
2+
# https://github.com/python/cpython/issues/90432: fixed in 3.12
3+
def foo():
4+
pas
5+
6+
\
7+
8+
def bar():
9+
pass

testsuite/test_E101.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""moved from testsuite files due to 3.12 making this a TokenError"""
2+
import unittest
3+
import sys
4+
5+
from testsuite.support import errors_from_src
6+
7+
8+
class E101Test(unittest.TestCase):
9+
def test_E101(self):
10+
errors = errors_from_src(
11+
'if True:\n'
12+
'\tprint(1) # tabs\n'
13+
' print(2) # spaces\n'
14+
)
15+
if sys.version_info >= (3, 12):
16+
self.assertEqual(errors, ['W191:2:1', 'E901:3:28'])
17+
else:
18+
self.assertEqual(errors, ['W191:2:1', 'E101:3:1'])

testsuite/test_E901.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""moved from testsuite files due to 3.12 changing syntax errors"""
2+
import unittest
3+
import sys
4+
5+
from testsuite.support import errors_from_src
6+
7+
8+
class E901Test(unittest.TestCase):
9+
def test_closing_brace(self):
10+
errors = errors_from_src('}\n')
11+
if sys.version_info < (3, 12):
12+
self.assertEqual(errors, ['E901:2:1'])
13+
else:
14+
self.assertEqual(errors, [])
15+
16+
def test_unclosed_brace(self):
17+
src = '''\
18+
if msg:
19+
errmsg = msg % progress.get(cr_dbname))
20+
21+
def lasting(self, duration=300):
22+
progress = self._progress.setdefault('foo', {}
23+
'''
24+
errors = errors_from_src(src)
25+
if sys.version_info < (3, 12):
26+
expected = ['E122:4:1', 'E225:4:27', 'E251:5:13', 'E251:5:15']
27+
else:
28+
expected = ['E122:4:1', 'E225:4:27', 'E251:5:13', 'E251:5:15', 'E901:5:1'] # noqa: E501
29+
self.assertEqual(errors, expected)

testsuite/test_api.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,18 @@ def test_check_nullbytes(self):
329329
count_errors = pep8style.input_file('stdin', lines=['\x00\n'])
330330

331331
stdout = sys.stdout.getvalue()
332-
if sys.version_info < (3, 12):
333-
expected = "stdin:1:1: E901 ValueError"
332+
if sys.version_info < (3, 11, 4):
333+
expected = ["stdin:1:1: E901 ValueError: source code string cannot contain null bytes"] # noqa: E501
334+
elif sys.version_info < (3, 12):
335+
expected = ["stdin:1:1: E901 SyntaxError: source code string cannot contain null bytes"] # noqa: E501
334336
else:
335-
expected = "stdin:1:1: E901 SyntaxError: source code string cannot contain null bytes" # noqa: E501
336-
self.assertTrue(stdout.startswith(expected),
337-
msg='Output %r does not start with %r' %
338-
(stdout, expected))
337+
expected = [
338+
"stdin:1:1: E901 SyntaxError: source code string cannot contain null bytes", # noqa: E501
339+
"stdin:1:1: E901 TokenError: source code cannot contain null bytes", # noqa: E501
340+
]
341+
self.assertEqual(stdout.splitlines(), expected)
339342
self.assertFalse(sys.stderr)
340-
self.assertEqual(count_errors, 1)
343+
self.assertEqual(count_errors, len(expected))
341344

342345
def test_styleguide_unmatched_triple_quotes(self):
343346
pycodestyle.register_check(DummyChecker, ['Z701'])
@@ -350,35 +353,22 @@ def test_styleguide_unmatched_triple_quotes(self):
350353
pep8style.input_file('stdin', lines=lines)
351354
stdout = sys.stdout.getvalue()
352355

353-
expected = 'stdin:2:5: E901 TokenError: EOF in multi-line string'
354-
self.assertTrue(expected in stdout)
355-
356-
def test_styleguide_continuation_line_outdented(self):
357-
pycodestyle.register_check(DummyChecker, ['Z701'])
358-
lines = [
359-
'def foo():\n',
360-
' pass\n',
361-
'\n',
362-
'\\\n',
363-
'\n',
364-
'def bar():\n',
365-
' pass\n',
366-
]
367-
368-
pep8style = pycodestyle.StyleGuide()
369-
count_errors = pep8style.input_file('stdin', lines=lines)
370-
self.assertEqual(count_errors, 2)
371-
stdout = sys.stdout.getvalue()
372-
expected = (
373-
'stdin:6:1: '
374-
'E122 continuation line missing indentation or outdented'
375-
)
376-
self.assertTrue(expected in stdout)
377-
expected = 'stdin:6:1: E302 expected 2 blank lines, found 1'
378-
self.assertTrue(expected in stdout)
379-
380-
# TODO: runner
381-
# TODO: input_file
356+
if sys.version_info < (3, 10):
357+
expected = [
358+
'stdin:2:5: E901 TokenError: EOF in multi-line string',
359+
'stdin:2:26: E901 SyntaxError: EOF while scanning triple-quoted string literal', # noqa: E501
360+
]
361+
elif sys.version_info < (3, 12):
362+
expected = [
363+
'stdin:2:5: E901 TokenError: EOF in multi-line string',
364+
'stdin:2:6: E901 SyntaxError: unterminated triple-quoted string literal (detected at line 2)', # noqa: E501
365+
]
366+
else:
367+
expected = [
368+
'stdin:2:6: E901 SyntaxError: unterminated triple-quoted string literal (detected at line 2)', # noqa: E501
369+
'stdin:2:6: E901 TokenError: EOF in multi-line string',
370+
]
371+
self.assertEqual(stdout.splitlines(), expected)
382372

383373
def test_styleguides_other_indent_size(self):
384374
pycodestyle.register_check(DummyChecker, ['Z701'])

0 commit comments

Comments
 (0)