diff options
author | Kevin Watters <kevinwatters@gmail.com> | 2014-02-26 18:59:35 -0800 |
---|---|---|
committer | Kevin Watters <kevinwatters@gmail.com> | 2014-02-26 18:59:35 -0800 |
commit | 627bf68c661337cf3a007fe9704e76144e288d3f (patch) | |
tree | 900bd8ed6cedad2d2ae0b0305b414f4972f03660 | |
parent | 8c6256cf81fda0f8e704acd3d0d275386285cd4c (diff) | |
parent | 32fb6d7280c653e9bb67f4080481327744339042 (diff) | |
download | pyflakes-627bf68c661337cf3a007fe9704e76144e288d3f.tar.gz |
Merge pull request #15 from asmeurer/syntaxerror
Fix a few launchpad bugs relating to syntax errors
-rw-r--r-- | pyflakes/reporter.py | 7 | ||||
-rw-r--r-- | pyflakes/test/test_api.py | 30 |
2 files changed, 21 insertions, 16 deletions
diff --git a/pyflakes/reporter.py b/pyflakes/reporter.py index 37b5429..4b8d31e 100644 --- a/pyflakes/reporter.py +++ b/pyflakes/reporter.py @@ -46,7 +46,7 @@ class Reporter(object): @ptype msg: C{unicode} @param lineno: The line number where the syntax error occurred. @ptype lineno: C{int} - @param offset: The column on which the syntax error occurred. + @param offset: The column on which the syntax error occurred, or None. @ptype offset: C{int} @param text: The source code containing the syntax error. @ptype text: C{unicode} @@ -54,7 +54,10 @@ class Reporter(object): line = text.splitlines()[-1] if offset is not None: offset = offset - (len(text) - len(line)) - self._stderr.write('%s:%d: %s\n' % (filename, lineno, msg)) + self._stderr.write('%s:%d:%d: %s\n' % (filename, lineno, offset + 1, + msg)) + else: + self._stderr.write('%s:%d: %s\n' % (filename, lineno, msg)) self._stderr.write(line) self._stderr.write('\n') if offset is not None: diff --git a/pyflakes/test/test_api.py b/pyflakes/test/test_api.py index 3571597..1d58d80 100644 --- a/pyflakes/test/test_api.py +++ b/pyflakes/test/test_api.py @@ -159,11 +159,11 @@ class TestReporter(TestCase): """ err = StringIO() reporter = Reporter(None, err) - reporter.syntaxError('foo.py', 'a problem', 3, 4, 'bad line of source') + reporter.syntaxError('foo.py', 'a problem', 3, 7, 'bad line of source') self.assertEqual( - ("foo.py:3: a problem\n" + ("foo.py:3:8: a problem\n" "bad line of source\n" - " ^\n"), + " ^\n"), err.getvalue()) def test_syntaxErrorNoOffset(self): @@ -192,12 +192,12 @@ class TestReporter(TestCase): 'more bad lines of source', ] reporter = Reporter(None, err) - reporter.syntaxError('foo.py', 'a problem', 3, len(lines[0]) + 5, + reporter.syntaxError('foo.py', 'a problem', 3, len(lines[0]) + 7, '\n'.join(lines)) self.assertEqual( - ("foo.py:3: a problem\n" + + ("foo.py:3:7: a problem\n" + lines[-1] + "\n" + - " ^\n"), + " ^\n"), err.getvalue()) def test_unexpectedError(self): @@ -320,7 +320,7 @@ def baz(): self.assertHasErrors( sourcePath, ["""\ -%s:8: invalid syntax +%s:8:11: invalid syntax '''quux''' ^ """ % (sourcePath,)]) @@ -334,7 +334,7 @@ def baz(): self.assertHasErrors( sourcePath, ["""\ -%s:1: unexpected EOF while parsing +%s:1:9: unexpected EOF while parsing def foo( ^ """ % (sourcePath,)]) @@ -348,7 +348,7 @@ def foo( self.assertHasErrors( sourcePath, ["""\ -%s:2: invalid syntax +%s:2:7: invalid syntax \tfoo = \t ^ """ % (sourcePath,)]) @@ -365,12 +365,13 @@ def foo(bar=baz, bax): """ sourcePath = self.makeTempFile(source) last_line = ' ^\n' if sys.version_info >= (3, 2) else '' + column = '8:' if sys.version_info >= (3, 2) else '' self.assertHasErrors( sourcePath, ["""\ -%s:1: non-default argument follows default argument +%s:1:%s non-default argument follows default argument def foo(bar=baz, bax): -%s""" % (sourcePath, last_line)]) +%s""" % (sourcePath, column, last_line)]) def test_nonKeywordAfterKeywordSyntaxError(self): """ @@ -383,12 +384,13 @@ foo(bar=baz, bax) """ sourcePath = self.makeTempFile(source) last_line = ' ^\n' if sys.version_info >= (3, 2) else '' + column = '13:' if sys.version_info >= (3, 2) else '' self.assertHasErrors( sourcePath, ["""\ -%s:1: non-keyword arg after keyword arg +%s:1:%s non-keyword arg after keyword arg foo(bar=baz, bax) -%s""" % (sourcePath, last_line)]) +%s""" % (sourcePath, column, last_line)]) def test_invalidEscape(self): """ @@ -404,7 +406,7 @@ foo(bar=baz, bax) # Column has been "fixed" since 3.2.4 and 3.3.1 col = 1 if ver >= (3, 3, 1) or ((3, 2, 4) <= ver < (3, 3)) else 2 decoding_error = """\ -%s:1: (unicode error) 'unicodeescape' codec can't decode bytes \ +%s:1:7: (unicode error) 'unicodeescape' codec can't decode bytes \ in position 0-%d: truncated \\xXX escape foo = '\\xyz' %s""" % (sourcePath, col, last_line) |