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''
b'' BR''
foo: int = 4
(foo): int = 3
((foo)): int = 3
foo.bar: int
foo[3]: int
for x in [1]:
try:
continue # Only the other continue and pass is an error.
@@ -80,8 +74,3 @@ def x():
a = *args, *args
error[(*args, *args)] = 3
*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.
"""
import sys
import warnings
from textwrap import dedent
import pytest
@@ -103,6 +104,15 @@ FAILING_EXAMPLES = [
'def f(x, x): pass',
'def x(): from math import *',
'nonlocal a',
# IndentationError
' foo',
'def x():\n 1\n 2',
'def x():\n 1\n 2',
'if 1:\nfoo',
]
GLOBAL_NONLOCAL_ERROR = [
dedent('''
def glob():
x = 3
@@ -199,16 +209,12 @@ FAILING_EXAMPLES = [
def z():
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):
tree = parso.parse(code, version=version)
config = ErrorFinderConfig()
@@ -265,10 +271,15 @@ def test_python_exception_matches(code):
error, = errors
actual = error.message
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):
with warnings.catch_warnings():
# We don't care about warnings where locals/globals misbehave here.
# It's as simple as either an error or not.
warnings.filterwarnings('ignore', category=SyntaxWarning)
try:
compile(code, '<unknown>', 'exec')
except (SyntaxError, IndentationError) as e: