Skip to content

Commit 2524a9c

Browse files
Make the code and tests compatible with 3.8-dev.
1 parent 7d4476e commit 2524a9c

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

pyflakes/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def ignore(self, node):
10861086
COMPARE = CALL = REPR = ATTRIBUTE = SUBSCRIPT = \
10871087
STARRED = NAMECONSTANT = handleChildren
10881088

1089-
NUM = STR = BYTES = ELLIPSIS = ignore
1089+
NUM = STR = BYTES = ELLIPSIS = CONSTANT = ignore
10901090

10911091
# "slice" type nodes
10921092
SLICE = EXTSLICE = INDEX = handleChildren

pyflakes/reporter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ def syntaxError(self, filename, msg, lineno, offset, text):
5353
"""
5454
line = text.splitlines()[-1]
5555
if offset is not None:
56-
offset = offset - (len(text) - len(line))
56+
if sys.version_info < (3, 8):
57+
offset = offset - (len(text) - len(line)) + 1
5758
self._stderr.write('%s:%d:%d: %s\n' %
58-
(filename, lineno, offset + 1, msg))
59+
(filename, lineno, offset, msg))
5960
else:
6061
self._stderr.write('%s:%d: %s\n' % (filename, lineno, msg))
6162
self._stderr.write(line)
6263
self._stderr.write('\n')
6364
if offset is not None:
64-
self._stderr.write(re.sub(r'\S', ' ', line[:offset]) +
65+
self._stderr.write(re.sub(r'\S', ' ', line[:offset - 1]) +
6566
"^\n")
6667

6768
def flake(self, message):

pyflakes/test/test_api.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ def test_syntaxError(self):
257257
"""
258258
err = StringIO()
259259
reporter = Reporter(None, err)
260-
reporter.syntaxError('foo.py', 'a problem', 3, 7, 'bad line of source')
260+
reporter.syntaxError('foo.py', 'a problem', 3,
261+
8 if sys.version_info >= (3, 8) else 7,
262+
'bad line of source')
261263
self.assertEqual(
262264
("foo.py:3:8: a problem\n"
263265
"bad line of source\n"
@@ -292,10 +294,11 @@ def test_multiLineSyntaxError(self):
292294
reporter = Reporter(None, err)
293295
reporter.syntaxError('foo.py', 'a problem', 3, len(lines[0]) + 7,
294296
'\n'.join(lines))
297+
column = 25 if sys.version_info >= (3, 8) else 7
295298
self.assertEqual(
296-
("foo.py:3:7: a problem\n" +
299+
("foo.py:3:%d: a problem\n" % column +
297300
lines[-1] + "\n" +
298-
" ^\n"),
301+
" " * (column - 1) + "^\n"),
299302
err.getvalue())
300303

301304
def test_unexpectedError(self):
@@ -424,13 +427,14 @@ def evaluate(source):
424427
else:
425428
message = 'invalid syntax'
426429

430+
column = 8 if sys.version_info >= (3, 8) else 11
427431
self.assertHasErrors(
428432
sourcePath,
429433
["""\
430-
%s:8:11: %s
434+
%s:8:%d: %s
431435
'''quux'''
432-
^
433-
""" % (sourcePath, message)])
436+
%s^
437+
""" % (sourcePath, column, message, ' ' * (column - 1))])
434438

435439
def test_eofSyntaxError(self):
436440
"""
@@ -483,14 +487,18 @@ def foo(bar=baz, bax):
483487
pass
484488
"""
485489
with self.makeTempFile(source) as sourcePath:
486-
last_line = ' ^\n' if ERROR_HAS_LAST_LINE else ''
487-
column = '8:' if ERROR_HAS_COL_NUM else ''
490+
if ERROR_HAS_LAST_LINE:
491+
column = 9 if sys.version_info >= (3, 8) else 8
492+
last_line = ' ' * (column - 1) + '^\n'
493+
columnstr = '%d:' % column
494+
else:
495+
last_line = columnstr = ''
488496
self.assertHasErrors(
489497
sourcePath,
490498
["""\
491499
%s:1:%s non-default argument follows default argument
492500
def foo(bar=baz, bax):
493-
%s""" % (sourcePath, column, last_line)])
501+
%s""" % (sourcePath, columnstr, last_line)])
494502

495503
def test_nonKeywordAfterKeywordSyntaxError(self):
496504
"""
@@ -502,8 +510,12 @@ def test_nonKeywordAfterKeywordSyntaxError(self):
502510
foo(bar=baz, bax)
503511
"""
504512
with self.makeTempFile(source) as sourcePath:
505-
last_line = ' ^\n' if ERROR_HAS_LAST_LINE else ''
506-
column = '13:' if ERROR_HAS_COL_NUM else ''
513+
if ERROR_HAS_LAST_LINE:
514+
column = 14 if sys.version_info >= (3, 8) else 13
515+
last_line = ' ' * (column - 1) + '^\n'
516+
columnstr = '%d:' % column
517+
else:
518+
last_line = columnstr = ''
507519

508520
if sys.version_info >= (3, 5):
509521
message = 'positional argument follows keyword argument'
@@ -515,7 +527,7 @@ def test_nonKeywordAfterKeywordSyntaxError(self):
515527
["""\
516528
%s:1:%s %s
517529
foo(bar=baz, bax)
518-
%s""" % (sourcePath, column, message, last_line)])
530+
%s""" % (sourcePath, columnstr, message, last_line)])
519531

520532
def test_invalidEscape(self):
521533
"""

pyflakes/test/test_doctests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ def doctest_stuff():
328328
m.DoctestSyntaxError).messages
329329
exc = exceptions[0]
330330
self.assertEqual(exc.lineno, 4)
331-
self.assertEqual(exc.col, 26)
331+
if sys.version_info >= (3, 8):
332+
self.assertEqual(exc.col, 18)
333+
else:
334+
self.assertEqual(exc.col, 26)
332335

333336
# PyPy error column offset is 0,
334337
# for the second and third line of the doctest
@@ -341,7 +344,7 @@ def doctest_stuff():
341344
self.assertEqual(exc.col, 16)
342345
exc = exceptions[2]
343346
self.assertEqual(exc.lineno, 6)
344-
if PYPY:
347+
if PYPY or sys.version_info >= (3, 8):
345348
self.assertEqual(exc.col, 13)
346349
else:
347350
self.assertEqual(exc.col, 18)
@@ -355,7 +358,7 @@ def doctest_stuff():
355358
"""
356359
''', m.DoctestSyntaxError).messages[0]
357360
self.assertEqual(exc.lineno, 5)
358-
if PYPY:
361+
if PYPY or sys.version_info >= (3, 8):
359362
self.assertEqual(exc.col, 13)
360363
else:
361364
self.assertEqual(exc.col, 16)

0 commit comments

Comments
 (0)