Fix a few things to get Python3.5 working.

This commit is contained in:
Dave Halter
2017-07-30 22:24:22 +02:00
parent 0906c0b634
commit 7f6bef19e1
3 changed files with 37 additions and 27 deletions

View File

@@ -12,12 +12,6 @@ from .__future__ import absolute_import
''r''u'' ''r''u''
b'' BR'' b'' BR''
foo: int = 4
(foo): int = 3
((foo)): int = 3
foo.bar: int
foo[3]: int
for x in [1]: for x in [1]:
try: try:
continue # Only the other continue and pass is an error. continue # Only the other continue and pass is an error.
@@ -80,8 +74,3 @@ def x():
a = *args, *args a = *args, *args
error[(*args, *args)] = 3 error[(*args, *args)] = 3
*args, *args *args, *args
def glob():
global x
y: foo = x

View File

@@ -0,0 +1,10 @@
foo: int = 4
(foo): int = 3
((foo)): int = 3
foo.bar: int
foo[3]: int
def glob():
global x
y: foo = x

View File

@@ -2,6 +2,7 @@
Testing if parso finds syntax errors and indentation errors. Testing if parso finds syntax errors and indentation errors.
""" """
import sys import sys
import warnings
from textwrap import dedent from textwrap import dedent
import pytest import pytest
@@ -103,6 +104,15 @@ FAILING_EXAMPLES = [
'def f(x, x): pass', 'def f(x, x): pass',
'def x(): from math import *', 'def x(): from math import *',
'nonlocal a', 'nonlocal a',
# IndentationError
' foo',
'def x():\n 1\n 2',
'def x():\n 1\n 2',
'if 1:\nfoo',
]
GLOBAL_NONLOCAL_ERROR = [
dedent(''' dedent('''
def glob(): def glob():
x = 3 x = 3
@@ -199,16 +209,12 @@ FAILING_EXAMPLES = [
def z(): def z():
nonlocal a nonlocal a
'''), '''),
# IndentationError
' foo',
'def x():\n 1\n 2',
'def x():\n 1\n 2',
'if 1:\nfoo',
] ]
if sys.version_info >= (3, 6):
FAILING_EXAMPLES += GLOBAL_NONLOCAL_ERROR
def _get_error_list(code, version=None): def _get_error_list(code, version=None):
tree = parso.parse(code, version=version) tree = parso.parse(code, version=version)
config = ErrorFinderConfig() config = ErrorFinderConfig()
@@ -265,17 +271,22 @@ def test_python_exception_matches(code):
error, = errors error, = errors
actual = error.message actual = error.message
assert wanted == actual assert wanted == actual
assert line_nr == error.start_pos[0] # Somehow in Python3.3 the SyntaxError().lineno is sometimes None
assert line_nr is None or line_nr == error.start_pos[0]
def _get_actual_exception(code): def _get_actual_exception(code):
try: with warnings.catch_warnings():
compile(code, '<unknown>', 'exec') # We don't care about warnings where locals/globals misbehave here.
except (SyntaxError, IndentationError) as e: # It's as simple as either an error or not.
wanted = e.__class__.__name__ + ': ' + e.msg warnings.filterwarnings('ignore', category=SyntaxWarning)
line_nr = e.lineno try:
else: compile(code, '<unknown>', 'exec')
assert False, "The piece of code should raise an exception." except (SyntaxError, IndentationError) as e:
wanted = e.__class__.__name__ + ': ' + e.msg
line_nr = e.lineno
else:
assert False, "The piece of code should raise an exception."
# SyntaxError # SyntaxError
# Python 2.6 has a bit different error messages here, so skip it. # Python 2.6 has a bit different error messages here, so skip it.