mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-09 06:04:54 +08:00
Fix a few things to get Python3.5 working.
This commit is contained in:
@@ -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
|
||||
|
||||
10
test/normalizer_issue_files/allowed_syntax_python3.6.py
Normal file
10
test/normalizer_issue_files/allowed_syntax_python3.6.py
Normal 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
|
||||
@@ -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,17 +271,22 @@ 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):
|
||||
try:
|
||||
compile(code, '<unknown>', 'exec')
|
||||
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."
|
||||
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:
|
||||
wanted = e.__class__.__name__ + ': ' + e.msg
|
||||
line_nr = e.lineno
|
||||
else:
|
||||
assert False, "The piece of code should raise an exception."
|
||||
|
||||
# SyntaxError
|
||||
# Python 2.6 has a bit different error messages here, so skip it.
|
||||
|
||||
Reference in New Issue
Block a user