Skip to content

Commit f3b1b44

Browse files
authored
fix syntax error offsets for python 3.10 (#635)
1 parent 95fe313 commit f3b1b44

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "pypy2", "pypy3"]
11+
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10-dev", "pypy2", "pypy3"]
1212
os: [ubuntu-latest]
1313
# Include py2 + minimum py3 + maximum py3 + pypy + pypy3 on Windows
1414
include:

pyflakes/test/test_api.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,25 @@ def evaluate(source):
441441
evaluate(source)
442442
except SyntaxError:
443443
e = sys.exc_info()[1]
444-
if not PYPY:
444+
if not PYPY and sys.version_info < (3, 10):
445445
self.assertTrue(e.text.count('\n') > 1)
446446
else:
447447
self.fail()
448448

449449
with self.makeTempFile(source) as sourcePath:
450450
if PYPY:
451451
message = 'end of file (EOF) while scanning triple-quoted string literal'
452+
elif sys.version_info >= (3, 10):
453+
message = 'unterminated triple-quoted string literal (detected at line 8)' # noqa: E501
452454
else:
453455
message = 'invalid syntax'
454456

455-
column = 8 if sys.version_info >= (3, 8) else 11
457+
if sys.version_info >= (3, 10):
458+
column = 12
459+
elif sys.version_info >= (3, 8):
460+
column = 8
461+
else:
462+
column = 11
456463
self.assertHasErrors(
457464
sourcePath,
458465
["""\
@@ -468,21 +475,25 @@ def test_eofSyntaxError(self):
468475
"""
469476
with self.makeTempFile("def foo(") as sourcePath:
470477
if PYPY:
471-
result = """\
472-
%s:1:7: parenthesis is never closed
473-
def foo(
474-
^
475-
""" % (sourcePath,)
478+
msg = 'parenthesis is never closed'
479+
elif sys.version_info >= (3, 10):
480+
msg = "'(' was never closed"
476481
else:
477-
result = """\
478-
%s:1:9: unexpected EOF while parsing
479-
def foo(
480-
^
481-
""" % (sourcePath,)
482+
msg = 'unexpected EOF while parsing'
482483

483-
self.assertHasErrors(
484-
sourcePath,
485-
[result])
484+
if PYPY:
485+
column = 7
486+
elif sys.version_info >= (3, 10):
487+
column = 8
488+
else:
489+
column = 9
490+
491+
spaces = ' ' * (column - 1)
492+
expected = '{}:1:{}: {}\ndef foo(\n{}^\n'.format(
493+
sourcePath, column, msg, spaces
494+
)
495+
496+
self.assertHasErrors(sourcePath, [expected])
486497

487498
def test_eofSyntaxErrorWithTab(self):
488499
"""
@@ -515,6 +526,8 @@ def foo(bar=baz, bax):
515526
if ERROR_HAS_LAST_LINE:
516527
if PYPY:
517528
column = 7
529+
elif sys.version_info >= (3, 10):
530+
column = 18
518531
elif sys.version_info >= (3, 9):
519532
column = 21
520533
elif sys.version_info >= (3, 8):

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
skip_missing_interpreters = True
33
envlist =
4-
py27,py34,py35,py36,py37,py38,pypy,pypy3
4+
py27,py35,py36,py37,py38,py39,py310,pypy,pypy3
55

66
[testenv]
77
deps = flake8==3.6.0

0 commit comments

Comments
 (0)