Skip to content

Commit 74bee7c

Browse files
authored
Update codeop.py from 3.13.5 (RustPython#6026)
1 parent 01edb93 commit 74bee7c

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

Lib/codeop.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# Caveat emptor: These flags are undocumented on purpose and depending
4545
# on their effect outside the standard library is **unsupported**.
4646
PyCF_DONT_IMPLY_DEDENT = 0x200
47+
PyCF_ONLY_AST = 0x400
4748
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
4849

4950
def _maybe_compile(compiler, source, filename, symbol):
@@ -73,23 +74,13 @@ def _maybe_compile(compiler, source, filename, symbol):
7374

7475
return compiler(source, filename, symbol, incomplete_input=False)
7576

76-
def _is_syntax_error(err1, err2):
77-
rep1 = repr(err1)
78-
rep2 = repr(err2)
79-
if "was never closed" in rep1 and "was never closed" in rep2:
80-
return False
81-
if rep1 == rep2:
82-
return True
83-
return False
84-
8577
def _compile(source, filename, symbol, incomplete_input=True):
8678
flags = 0
8779
if incomplete_input:
8880
flags |= PyCF_ALLOW_INCOMPLETE_INPUT
8981
flags |= PyCF_DONT_IMPLY_DEDENT
9082
return compile(source, filename, symbol, flags)
9183

92-
9384
def compile_command(source, filename="<input>", symbol="single"):
9485
r"""Compile a command and determine whether it is incomplete.
9586
@@ -119,12 +110,14 @@ class Compile:
119110
def __init__(self):
120111
self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
121112

122-
def __call__(self, source, filename, symbol, **kwargs):
123-
flags = self.flags
113+
def __call__(self, source, filename, symbol, flags=0, **kwargs):
114+
flags |= self.flags
124115
if kwargs.get('incomplete_input', True) is False:
125116
flags &= ~PyCF_DONT_IMPLY_DEDENT
126117
flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT
127118
codeob = compile(source, filename, symbol, flags, True)
119+
if flags & PyCF_ONLY_AST:
120+
return codeob # this is an ast.Module in this case
128121
for feature in _features:
129122
if codeob.co_flags & feature.compiler_flag:
130123
self.flags |= feature.compiler_flag

Lib/test/test_codeop.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ def test_incomplete(self):
227227
ai("(x for x in")
228228
ai("(x for x in (")
229229

230+
ai('a = f"""')
231+
ai('a = \\')
232+
230233
def test_invalid(self):
231234
ai = self.assertInvalid
232235
ai("a b")
@@ -300,12 +303,11 @@ def test_warning(self):
300303
warnings.simplefilter('error', SyntaxWarning)
301304
compile_command(r"'\e'", symbol='exec')
302305

303-
# TODO: RUSTPYTHON
304-
#def test_incomplete_warning(self):
305-
# with warnings.catch_warnings(record=True) as w:
306-
# warnings.simplefilter('always')
307-
# self.assertIncomplete("'\\e' + (")
308-
# self.assertEqual(w, [])
306+
def test_incomplete_warning(self):
307+
with warnings.catch_warnings(record=True) as w:
308+
warnings.simplefilter('always')
309+
self.assertIncomplete("'\\e' + (")
310+
self.assertEqual(w, [])
309311

310312
# TODO: RUSTPYTHON
311313
@unittest.expectedFailure

0 commit comments

Comments
 (0)