mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update codeop.py from 3.13.5 (#6026)
This commit is contained in:
17
Lib/codeop.py
vendored
17
Lib/codeop.py
vendored
@@ -44,6 +44,7 @@ __all__ = ["compile_command", "Compile", "CommandCompiler"]
|
||||
# Caveat emptor: These flags are undocumented on purpose and depending
|
||||
# on their effect outside the standard library is **unsupported**.
|
||||
PyCF_DONT_IMPLY_DEDENT = 0x200
|
||||
PyCF_ONLY_AST = 0x400
|
||||
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
|
||||
|
||||
def _maybe_compile(compiler, source, filename, symbol):
|
||||
@@ -73,15 +74,6 @@ def _maybe_compile(compiler, source, filename, symbol):
|
||||
|
||||
return compiler(source, filename, symbol, incomplete_input=False)
|
||||
|
||||
def _is_syntax_error(err1, err2):
|
||||
rep1 = repr(err1)
|
||||
rep2 = repr(err2)
|
||||
if "was never closed" in rep1 and "was never closed" in rep2:
|
||||
return False
|
||||
if rep1 == rep2:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _compile(source, filename, symbol, incomplete_input=True):
|
||||
flags = 0
|
||||
if incomplete_input:
|
||||
@@ -89,7 +81,6 @@ def _compile(source, filename, symbol, incomplete_input=True):
|
||||
flags |= PyCF_DONT_IMPLY_DEDENT
|
||||
return compile(source, filename, symbol, flags)
|
||||
|
||||
|
||||
def compile_command(source, filename="<input>", symbol="single"):
|
||||
r"""Compile a command and determine whether it is incomplete.
|
||||
|
||||
@@ -119,12 +110,14 @@ class Compile:
|
||||
def __init__(self):
|
||||
self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
|
||||
|
||||
def __call__(self, source, filename, symbol, **kwargs):
|
||||
flags = self.flags
|
||||
def __call__(self, source, filename, symbol, flags=0, **kwargs):
|
||||
flags |= self.flags
|
||||
if kwargs.get('incomplete_input', True) is False:
|
||||
flags &= ~PyCF_DONT_IMPLY_DEDENT
|
||||
flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT
|
||||
codeob = compile(source, filename, symbol, flags, True)
|
||||
if flags & PyCF_ONLY_AST:
|
||||
return codeob # this is an ast.Module in this case
|
||||
for feature in _features:
|
||||
if codeob.co_flags & feature.compiler_flag:
|
||||
self.flags |= feature.compiler_flag
|
||||
|
||||
14
Lib/test/test_codeop.py
vendored
14
Lib/test/test_codeop.py
vendored
@@ -227,6 +227,9 @@ class CodeopTests(unittest.TestCase):
|
||||
ai("(x for x in")
|
||||
ai("(x for x in (")
|
||||
|
||||
ai('a = f"""')
|
||||
ai('a = \\')
|
||||
|
||||
def test_invalid(self):
|
||||
ai = self.assertInvalid
|
||||
ai("a b")
|
||||
@@ -300,12 +303,11 @@ class CodeopTests(unittest.TestCase):
|
||||
warnings.simplefilter('error', SyntaxWarning)
|
||||
compile_command(r"'\e'", symbol='exec')
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
#def test_incomplete_warning(self):
|
||||
# with warnings.catch_warnings(record=True) as w:
|
||||
# warnings.simplefilter('always')
|
||||
# self.assertIncomplete("'\\e' + (")
|
||||
# self.assertEqual(w, [])
|
||||
def test_incomplete_warning(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always')
|
||||
self.assertIncomplete("'\\e' + (")
|
||||
self.assertEqual(w, [])
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
|
||||
Reference in New Issue
Block a user