mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-24 13:11:40 +08:00
Compare commits
8 Commits
v0.8.4
...
9ddffca4da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ddffca4da | ||
|
|
06db036e23 | ||
|
|
c792ae546c | ||
|
|
1c01dafc2b | ||
|
|
1ca6b1f3e8 | ||
|
|
5a9349ae58 | ||
|
|
279fd6903e | ||
|
|
e255b69cb8 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
|
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
|
||||||
experimental: [false]
|
experimental: [false]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|||||||
16
.readthedocs.yml
Normal file
16
.readthedocs.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
python:
|
||||||
|
install:
|
||||||
|
- method: pip
|
||||||
|
path: .
|
||||||
|
extra_requirements:
|
||||||
|
- docs
|
||||||
|
|
||||||
|
submodules:
|
||||||
|
include: all
|
||||||
|
|
||||||
|
build:
|
||||||
|
os: ubuntu-22.04
|
||||||
|
tools:
|
||||||
|
python: "3.11"
|
||||||
@@ -88,8 +88,7 @@ Acknowledgements
|
|||||||
|
|
||||||
- Guido van Rossum (@gvanrossum) for creating the parser generator pgen2
|
- Guido van Rossum (@gvanrossum) for creating the parser generator pgen2
|
||||||
(originally used in lib2to3).
|
(originally used in lib2to3).
|
||||||
- `Salome Schneider <https://www.crepes-schnaegg.ch/cr%C3%AApes-schn%C3%A4gg/kunst-f%C3%BCrs-cr%C3%AApes-mobil/>`_
|
- Salome Schneider for the extremely awesome parso logo.
|
||||||
for the extremely awesome parso logo.
|
|
||||||
|
|
||||||
|
|
||||||
.. _jedi: https://github.com/davidhalter/jedi
|
.. _jedi: https://github.com/davidhalter/jedi
|
||||||
|
|||||||
9
SECURITY.md
Normal file
9
SECURITY.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
If security issues arise, we will try to fix those as soon as possible.
|
||||||
|
|
||||||
|
Due to Parso's nature, Security Issues will probably be extremely rare, but we will of course treat them seriously.
|
||||||
|
|
||||||
|
## Reporting Security Problems
|
||||||
|
|
||||||
|
If you need to report a security vulnerability, please send an email to davidhalter88@gmail.com. Typically, I will respond in the next few business days.
|
||||||
@@ -29,7 +29,6 @@ FAILING_EXAMPLES = [
|
|||||||
'from foo import a,',
|
'from foo import a,',
|
||||||
'from __future__ import whatever',
|
'from __future__ import whatever',
|
||||||
'from __future__ import braces',
|
'from __future__ import braces',
|
||||||
'from .__future__ import whatever',
|
|
||||||
'def f(x=3, y): pass',
|
'def f(x=3, y): pass',
|
||||||
'lambda x=3, y: x',
|
'lambda x=3, y: x',
|
||||||
'__debug__ = 1',
|
'__debug__ = 1',
|
||||||
@@ -216,7 +215,6 @@ FAILING_EXAMPLES = [
|
|||||||
'f"{\'\\\'}"',
|
'f"{\'\\\'}"',
|
||||||
'f"{#}"',
|
'f"{#}"',
|
||||||
"f'{1!b}'",
|
"f'{1!b}'",
|
||||||
"f'{1:{5:{3}}}'",
|
|
||||||
"f'{'",
|
"f'{'",
|
||||||
"f'{'",
|
"f'{'",
|
||||||
"f'}'",
|
"f'}'",
|
||||||
@@ -227,8 +225,6 @@ FAILING_EXAMPLES = [
|
|||||||
"f'{1;1}'",
|
"f'{1;1}'",
|
||||||
"f'{a;}'",
|
"f'{a;}'",
|
||||||
"f'{b\"\" \"\"}'",
|
"f'{b\"\" \"\"}'",
|
||||||
# f-string expression part cannot include a backslash
|
|
||||||
r'''f"{'\n'}"''',
|
|
||||||
|
|
||||||
'async def foo():\n yield x\n return 1',
|
'async def foo():\n yield x\n return 1',
|
||||||
'async def foo():\n yield x\n return 1',
|
'async def foo():\n yield x\n return 1',
|
||||||
@@ -413,3 +409,17 @@ if sys.version_info[:2] >= (3, 8):
|
|||||||
FAILING_EXAMPLES += [
|
FAILING_EXAMPLES += [
|
||||||
"f'{1=!b}'",
|
"f'{1=!b}'",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if sys.version_info[:2] < (3, 12):
|
||||||
|
FAILING_EXAMPLES += [
|
||||||
|
# f-string expression part cannot include a backslash before 3.12
|
||||||
|
r'''f"{'\n'}"''',
|
||||||
|
# this compiles successfully but fails when evaluated in 3.12
|
||||||
|
"f'{1:{5:{3}}}'",
|
||||||
|
]
|
||||||
|
|
||||||
|
if sys.version_info[:2] < (3, 13):
|
||||||
|
# this compiles successfully but fails when evaluated in 3.13
|
||||||
|
FAILING_EXAMPLES += [
|
||||||
|
'from .__future__ import whatever',
|
||||||
|
]
|
||||||
|
|||||||
@@ -118,25 +118,57 @@ def _get_actual_exception(code):
|
|||||||
assert False, "The piece of code should raise an exception."
|
assert False, "The piece of code should raise an exception."
|
||||||
|
|
||||||
# SyntaxError
|
# SyntaxError
|
||||||
if wanted == 'SyntaxError: assignment to keyword':
|
# Some errors have changed error message in later versions of Python,
|
||||||
|
# and we give a translation table here. We deal with special cases
|
||||||
|
# below.
|
||||||
|
translations = {
|
||||||
|
'SyntaxError: f-string: unterminated string':
|
||||||
|
'SyntaxError: EOL while scanning string literal',
|
||||||
|
"SyntaxError: f-string: expecting '}'":
|
||||||
|
'SyntaxError: EOL while scanning string literal',
|
||||||
|
'SyntaxError: f-string: empty expression not allowed':
|
||||||
|
'SyntaxError: invalid syntax',
|
||||||
|
"SyntaxError: f-string expression part cannot include '#'":
|
||||||
|
'SyntaxError: invalid syntax',
|
||||||
|
"SyntaxError: f-string: single '}' is not allowed":
|
||||||
|
'SyntaxError: invalid syntax',
|
||||||
|
'SyntaxError: cannot use starred expression here':
|
||||||
|
"SyntaxError: can't use starred expression here",
|
||||||
|
'SyntaxError: f-string: cannot use starred expression here':
|
||||||
|
"SyntaxError: f-string: can't use starred expression here",
|
||||||
|
'SyntaxError: unterminated string literal':
|
||||||
|
'SyntaxError: EOL while scanning string literal',
|
||||||
|
'SyntaxError: parameter without a default follows parameter with a default':
|
||||||
|
'SyntaxError: non-default argument follows default argument',
|
||||||
|
"SyntaxError: 'yield from' outside function":
|
||||||
|
"SyntaxError: 'yield' outside function",
|
||||||
|
"SyntaxError: f-string: valid expression required before '}'":
|
||||||
|
'SyntaxError: invalid syntax',
|
||||||
|
"SyntaxError: '{' was never closed":
|
||||||
|
'SyntaxError: invalid syntax',
|
||||||
|
"SyntaxError: f-string: invalid conversion character 'b': expected 's', 'r', or 'a'":
|
||||||
|
"SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'",
|
||||||
|
"SyntaxError: (value error) Invalid format specifier ' 5' for object of type 'int'":
|
||||||
|
'SyntaxError: f-string: expressions nested too deeply',
|
||||||
|
"SyntaxError: f-string: expecting a valid expression after '{'":
|
||||||
|
'SyntaxError: f-string: invalid syntax',
|
||||||
|
"SyntaxError: f-string: expecting '=', or '!', or ':', or '}'":
|
||||||
|
'SyntaxError: f-string: invalid syntax',
|
||||||
|
"SyntaxError: f-string: expecting '=', or '!', or ':', or '}'":
|
||||||
|
'SyntaxError: f-string: invalid syntax',
|
||||||
|
}
|
||||||
|
|
||||||
|
if wanted in translations:
|
||||||
|
wanted = translations[wanted]
|
||||||
|
elif wanted == 'SyntaxError: assignment to keyword':
|
||||||
return [wanted, "SyntaxError: can't assign to keyword",
|
return [wanted, "SyntaxError: can't assign to keyword",
|
||||||
'SyntaxError: cannot assign to __debug__'], line_nr
|
'SyntaxError: cannot assign to __debug__'], line_nr
|
||||||
elif wanted == 'SyntaxError: f-string: unterminated string':
|
|
||||||
wanted = 'SyntaxError: EOL while scanning string literal'
|
|
||||||
elif wanted == 'SyntaxError: f-string expression part cannot include a backslash':
|
elif wanted == 'SyntaxError: f-string expression part cannot include a backslash':
|
||||||
return [
|
return [
|
||||||
wanted,
|
wanted,
|
||||||
"SyntaxError: EOL while scanning string literal",
|
"SyntaxError: EOL while scanning string literal",
|
||||||
"SyntaxError: unexpected character after line continuation character",
|
"SyntaxError: unexpected character after line continuation character",
|
||||||
], line_nr
|
], line_nr
|
||||||
elif wanted == "SyntaxError: f-string: expecting '}'":
|
|
||||||
wanted = 'SyntaxError: EOL while scanning string literal'
|
|
||||||
elif wanted == 'SyntaxError: f-string: empty expression not allowed':
|
|
||||||
wanted = 'SyntaxError: invalid syntax'
|
|
||||||
elif wanted == "SyntaxError: f-string expression part cannot include '#'":
|
|
||||||
wanted = 'SyntaxError: invalid syntax'
|
|
||||||
elif wanted == "SyntaxError: f-string: single '}' is not allowed":
|
|
||||||
wanted = 'SyntaxError: invalid syntax'
|
|
||||||
elif "Maybe you meant '==' instead of '='?" in wanted:
|
elif "Maybe you meant '==' instead of '='?" in wanted:
|
||||||
wanted = wanted.removesuffix(" here. Maybe you meant '==' instead of '='?")
|
wanted = wanted.removesuffix(" here. Maybe you meant '==' instead of '='?")
|
||||||
elif re.match(
|
elif re.match(
|
||||||
@@ -148,17 +180,27 @@ def _get_actual_exception(code):
|
|||||||
wanted,
|
wanted,
|
||||||
):
|
):
|
||||||
wanted = 'SyntaxError: EOF while scanning triple-quoted string literal'
|
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(
|
elif re.match(
|
||||||
r"IndentationError: expected an indented block after '[^']*' statement on line \d",
|
r"IndentationError: expected an indented block after '[^']*' statement on line \d",
|
||||||
wanted,
|
wanted,
|
||||||
):
|
):
|
||||||
wanted = 'IndentationError: expected an indented block'
|
wanted = 'IndentationError: expected an indented block'
|
||||||
elif wanted == 'SyntaxError: unterminated string literal':
|
# The following two errors are produced for both some f-strings and
|
||||||
wanted = 'SyntaxError: EOL while scanning string literal'
|
# some non-f-strings in Python 3.13:
|
||||||
|
elif wanted == "SyntaxError: can't use starred expression here":
|
||||||
|
wanted = [
|
||||||
|
"SyntaxError: can't use starred expression here",
|
||||||
|
"SyntaxError: f-string: can't use starred expression here"
|
||||||
|
]
|
||||||
|
elif wanted == 'SyntaxError: cannot mix bytes and nonbytes literals':
|
||||||
|
wanted = [
|
||||||
|
'SyntaxError: cannot mix bytes and nonbytes literals',
|
||||||
|
'SyntaxError: f-string: cannot mix bytes and nonbytes literals'
|
||||||
|
]
|
||||||
|
|
||||||
|
if isinstance(wanted, list):
|
||||||
|
return wanted, line_nr
|
||||||
|
else:
|
||||||
return [wanted], line_nr
|
return [wanted], line_nr
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user