Merge pull request #211 from jspricke/test_python3_10

Fix unit tests in Python 3.10 (Closes: #192)
This commit is contained in:
Dave Halter
2022-12-06 20:20:10 +00:00
committed by GitHub
4 changed files with 66 additions and 15 deletions

View File

@@ -29,11 +29,8 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
python-version: ['3.6', '3.7', '3.8', '3.9'] python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
experimental: [false] experimental: [false]
# include:
# - python-version: '3.10-dev'
# experimental: true
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import codecs import codecs
import sys
import warnings import warnings
import re import re
from contextlib import contextmanager from contextlib import contextmanager
@@ -33,7 +34,10 @@ def _get_rhs_name(node, version):
return "literal" return "literal"
else: else:
if second.children[1] == ":" or second.children[0] == "**": if second.children[1] == ":" or second.children[0] == "**":
return "dict display" if version < (3, 10):
return "dict display"
else:
return "dict literal"
else: else:
return "set display" return "set display"
elif ( elif (
@@ -47,7 +51,10 @@ def _get_rhs_name(node, version):
elif first == "[": elif first == "[":
return "list" return "list"
elif first == "{" and second == "}": elif first == "{" and second == "}":
return "dict display" if version < (3, 10):
return "dict display"
else:
return "dict literal"
elif first == "{" and len(node.children) > 2: elif first == "{" and len(node.children) > 2:
return "set display" return "set display"
elif type_ == "keyword": elif type_ == "keyword":
@@ -58,7 +65,10 @@ def _get_rhs_name(node, version):
else: else:
return str(node.value) return str(node.value)
elif type_ == "operator" and node.value == "...": elif type_ == "operator" and node.value == "...":
return "Ellipsis" if version < (3, 10):
return "Ellipsis"
else:
return "ellipsis"
elif type_ == "comparison": elif type_ == "comparison":
return "comparison" return "comparison"
elif type_ in ("string", "number", "strings"): elif type_ in ("string", "number", "strings"):
@@ -83,7 +93,10 @@ def _get_rhs_name(node, version):
or "_test" in type_ or "_test" in type_
or type_ in ("term", "factor") or type_ in ("term", "factor")
): ):
return "operator" if version < (3, 10):
return "operator"
else:
return "expression"
elif type_ == "star_expr": elif type_ == "star_expr":
return "starred" return "starred"
elif type_ == "testlist_star_expr": elif type_ == "testlist_star_expr":
@@ -610,7 +623,10 @@ class _NameChecks(SyntaxRule):
@ErrorFinder.register_rule(type='string') @ErrorFinder.register_rule(type='string')
class _StringChecks(SyntaxRule): class _StringChecks(SyntaxRule):
message = "bytes can only contain ASCII literal characters." if sys.version_info < (3, 10):
message = "bytes can only contain ASCII literal characters."
else:
message = "bytes can only contain ASCII literal characters"
def is_issue(self, leaf): def is_issue(self, leaf):
string_prefix = leaf.string_prefix.lower() string_prefix = leaf.string_prefix.lower()
@@ -1043,14 +1059,20 @@ class _CheckAssignmentRule(SyntaxRule):
error = 'literal' error = 'literal'
else: else:
if second.children[1] == ':': if second.children[1] == ':':
error = 'dict display' if self._normalizer.version < (3, 10):
error = 'dict display'
else:
error = 'dict literal'
else: else:
error = 'set display' error = 'set display'
elif first == "{" and second == "}": elif first == "{" and second == "}":
if self._normalizer.version < (3, 8): if self._normalizer.version < (3, 8):
error = 'literal' error = 'literal'
else: else:
error = "dict display" if self._normalizer.version < (3, 10):
error = "dict display"
else:
error = "dict literal"
elif first == "{" and len(node.children) > 2: elif first == "{" and len(node.children) > 2:
if self._normalizer.version < (3, 8): if self._normalizer.version < (3, 8):
error = 'literal' error = 'literal'
@@ -1083,7 +1105,10 @@ class _CheckAssignmentRule(SyntaxRule):
error = str(node.value) error = str(node.value)
elif type_ == 'operator': elif type_ == 'operator':
if node.value == '...': if node.value == '...':
error = 'Ellipsis' if self._normalizer.version < (3, 10):
error = 'Ellipsis'
else:
error = 'ellipsis'
elif type_ == 'comparison': elif type_ == 'comparison':
error = 'comparison' error = 'comparison'
elif type_ in ('string', 'number', 'strings'): elif type_ in ('string', 'number', 'strings'):
@@ -1098,7 +1123,10 @@ class _CheckAssignmentRule(SyntaxRule):
if node.children[0] == 'await': if node.children[0] == 'await':
error = 'await expression' error = 'await expression'
elif node.children[-2] == '**': elif node.children[-2] == '**':
error = 'operator' if self._normalizer.version < (3, 10):
error = 'operator'
else:
error = 'expression'
else: else:
# Has a trailer # Has a trailer
trailer = node.children[-1] trailer = node.children[-1]
@@ -1120,7 +1148,10 @@ class _CheckAssignmentRule(SyntaxRule):
elif ('expr' in type_ and type_ != 'star_expr' # is a substring elif ('expr' in type_ and type_ != 'star_expr' # is a substring
or '_test' in type_ or '_test' in type_
or type_ in ('term', 'factor')): or type_ in ('term', 'factor')):
error = 'operator' if self._normalizer.version < (3, 10):
error = 'operator'
else:
error = 'expression'
elif type_ == "star_expr": elif type_ == "star_expr":
if is_deletion: if is_deletion:
if self._normalizer.version >= (3, 9): if self._normalizer.version >= (3, 9):

View File

@@ -47,7 +47,7 @@ setup(
], ],
extras_require={ extras_require={
'testing': [ 'testing': [
'pytest<6.0.0', 'pytest',
'docopt', 'docopt',
], ],
'qa': [ 'qa': [

View File

@@ -1,6 +1,7 @@
""" """
Testing if parso finds syntax errors and indentation errors. Testing if parso finds syntax errors and indentation errors.
""" """
import re
import sys import sys
import warnings import warnings
@@ -136,6 +137,28 @@ def _get_actual_exception(code):
wanted = 'SyntaxError: invalid syntax' wanted = 'SyntaxError: invalid syntax'
elif wanted == "SyntaxError: f-string: single '}' is not allowed": elif wanted == "SyntaxError: f-string: single '}' is not allowed":
wanted = 'SyntaxError: invalid syntax' wanted = 'SyntaxError: invalid syntax'
elif "Maybe you meant '==' instead of '='?" in wanted:
wanted = wanted.removesuffix(" here. Maybe you meant '==' instead of '='?")
elif re.match(
r"SyntaxError: unterminated string literal \(detected at line \d+\)", wanted
):
wanted = "SyntaxError: EOL while scanning string literal"
elif re.match(
r"SyntaxError: unterminated triple-quoted string literal \(detected at line \d+\)",
wanted,
):
wanted = 'SyntaxError: EOF while scanning triple-quoted string literal'
elif wanted == 'SyntaxError: cannot use starred expression here':
wanted = "SyntaxError: can't use starred expression here"
elif wanted == 'SyntaxError: f-string: cannot use starred expression here':
wanted = "SyntaxError: f-string: can't use starred expression here"
elif re.match(
r"IndentationError: expected an indented block after '[^']*' statement on line \d",
wanted,
):
wanted = 'IndentationError: expected an indented block'
elif wanted == 'SyntaxError: unterminated string literal':
wanted = 'SyntaxError: EOL while scanning string literal'
return [wanted], line_nr return [wanted], line_nr