Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Lib/codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
PyCF_ONLY_AST = 0x400
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000

def _maybe_compile(compiler, source, filename, symbol):
def _maybe_compile(compiler, source, filename, symbol, flags):
# Check for source consisting of only blank lines and comments.
for line in source.split("\n"):
line = line.strip()
Expand All @@ -61,10 +61,10 @@ def _maybe_compile(compiler, source, filename, symbol):
with warnings.catch_warnings():
warnings.simplefilter("ignore", (SyntaxWarning, DeprecationWarning))
try:
compiler(source, filename, symbol)
compiler(source, filename, symbol, flags=flags)
except SyntaxError: # Let other compile() errors propagate.
try:
compiler(source + "\n", filename, symbol)
compiler(source + "\n", filename, symbol, flags=flags)
return None
except _IncompleteInputError as e:
return None
Expand All @@ -74,14 +74,13 @@ def _maybe_compile(compiler, source, filename, symbol):

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

def _compile(source, filename, symbol, incomplete_input=True):
flags = 0
def _compile(source, filename, symbol, incomplete_input=True, *, flags=0):
if incomplete_input:
flags |= PyCF_ALLOW_INCOMPLETE_INPUT
flags |= PyCF_DONT_IMPLY_DEDENT
return compile(source, filename, symbol, flags)

def compile_command(source, filename="<input>", symbol="single"):
def compile_command(source, filename="<input>", symbol="single", flags=0):
r"""Compile a command and determine whether it is incomplete.

Arguments:
Expand All @@ -100,7 +99,7 @@ def compile_command(source, filename="<input>", symbol="single"):
syntax error (OverflowError and ValueError can be produced by
malformed literals).
"""
return _maybe_compile(_compile, source, filename, symbol)
return _maybe_compile(_compile, source, filename, symbol, flags)

class Compile:
"""Instances of this class behave much like the built-in compile
Expand Down Expand Up @@ -152,4 +151,4 @@ def __call__(self, source, filename="<input>", symbol="single"):
syntax error (OverflowError and ValueError can be produced by
malformed literals).
"""
return _maybe_compile(self.compiler, source, filename, symbol)
return _maybe_compile(self.compiler, source, filename, symbol, flags=self.compiler.flags)
2 changes: 2 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,7 @@ def test_log_destroyed_pending_task(self):
return super().test_log_destroyed_pending_task()



@unittest.skipUnless(hasattr(futures, '_CFuture') and
hasattr(tasks, '_CTask'),
'requires the C _asyncio module')
Expand Down Expand Up @@ -3007,6 +3008,7 @@ def test_log_destroyed_pending_task(self):
return super().test_log_destroyed_pending_task()



@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_cmd_line_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,6 @@ def test_dash_m_main_traceback(self):
self.assertIn(b'Exception in __main__ module', err)
self.assertIn(b'Traceback', err)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_pep_409_verbiage(self):
# Make sure PEP 409 syntax properly suppresses
# the context of an exception
Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_code_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_console_stderr(self):
else:
raise AssertionError("no console stdout")

@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax']
def test_syntax_error(self):
self.infunc.side_effect = ["def f():",
" x = ?",
Expand Down Expand Up @@ -166,7 +165,6 @@ def test_sysexcepthook(self):
' File "<console>", line 2, in f\n',
'ValueError: BOOM!\n'])

@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax\n']
def test_sysexcepthook_syntax_error(self):
self.infunc.side_effect = ["def f():",
" x = ?",
Expand Down Expand Up @@ -285,7 +283,6 @@ def test_exit_msg(self):
self.assertEqual(err_msg, ['write', (expected,), {}])


@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError\n' not found in 'Python <MagicMock name=\'sys.version\' id=\'94615517503920\'> on <MagicMock name=\'sys.platform\' id=\'94615517656384\'>\nType "help", "copyright", "credits" or "license" for more information.\n(InteractiveConsole)\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError: \n\nnow exiting InteractiveConsole...\n'
def test_cause_tb(self):
self.infunc.side_effect = ["raise ValueError('') from AttributeError",
EOFError('Finished')]
Expand Down
16 changes: 5 additions & 11 deletions Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def assertInvalid(self, str, symbol='single', is_syntax=1):
except OverflowError:
self.assertTrue(not is_syntax)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: <code object <module> at 0xc99532080 file "<input>", line 1> != <code object <module> at 0xc99532f80 file "<input>", line 1>
def test_valid(self):
av = self.assertValid

Expand Down Expand Up @@ -94,8 +93,7 @@ def test_valid(self):
av("def f():\n pass\n#foo\n")
av("@a.b.c\ndef f():\n pass\n")

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: <code object <module> at 0xc99532080 file "<input>", line 1> != None
def test_incomplete(self):
ai = self.assertIncomplete

Expand Down Expand Up @@ -282,13 +280,12 @@ def test_filename(self):
self.assertNotEqual(compile_command("a = 1\n", "abc").co_filename,
compile("a = 1\n", "def", 'single').co_filename)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 2
def test_warning(self):
# Test that the warning is only returned once.
with warnings_helper.check_warnings(
('"is" with \'str\' literal', SyntaxWarning),
("invalid escape sequence", SyntaxWarning),
('"\\\\e" is an invalid escape sequence', SyntaxWarning),
) as w:
compile_command(r"'\e' is 0")
self.assertEqual(len(w.warnings), 2)
Expand All @@ -309,8 +306,7 @@ def test_incomplete_warning(self):
self.assertIncomplete("'\\e' + (")
self.assertEqual(w, [])

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 0 != 1
def test_invalid_warning(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
Expand All @@ -325,8 +321,6 @@ def assertSyntaxErrorMatches(self, code, message):
with self.assertRaisesRegex(SyntaxError, message):
compile_command(code, symbol='exec')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_syntax_errors(self):
self.assertSyntaxErrorMatches(
dedent("""\
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,6 @@ def __exit__(self, *exc_details):
self.assertIsInstance(inner_exc, ValueError)
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exit_exception_chaining(self):
# Ensure exception chaining matches the reference behaviour
def raise_exc(exc):
Expand Down Expand Up @@ -957,8 +955,6 @@ def suppress_exc(*exc_details):
self.assertIsInstance(inner_exc, ValueError)
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exit_exception_explicit_none_context(self):
# Ensure ExitStack chaining matches actual nested `with` statements
# regarding explicit __context__ = None.
Expand Down Expand Up @@ -1053,8 +1049,6 @@ def gets_the_context_right(exc):
self.assertIsNone(
exc.__context__.__context__.__context__.__context__)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exit_exception_with_existing_context(self):
# Addresses a lack of test coverage discovered after checking in a
# fix for issue 20317 that still contained debugging code.
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_contextlib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ async def __aenter__(self):
await stack.enter_async_context(LacksExit())
self.assertFalse(stack._exit_callbacks)

@unittest.expectedFailure # TODO: RUSTPYTHON
async def test_async_exit_exception_chaining(self):
# Ensure exception chaining matches the reference behaviour
async def raise_exc(exc):
Expand Down Expand Up @@ -682,7 +681,6 @@ async def suppress_exc(*exc_details):
self.assertIsInstance(inner_exc, ValueError)
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)

@unittest.expectedFailure # TODO: RUSTPYTHON
async def test_async_exit_exception_explicit_none_context(self):
# Ensure AsyncExitStack chaining matches actual nested `with` statements
# regarding explicit __context__ = None.
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,6 @@ def __del__(self):
f"deallocator {obj_repr}")
self.assertIsNotNone(cm.unraisable.exc_traceback)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_unhandled(self):
# Check for sensible reporting of unhandled exceptions
for exc_type in (ValueError, BrokenStrException):
Expand Down Expand Up @@ -2283,7 +2282,6 @@ def test_multiline_not_highlighted(self):
class SyntaxErrorTests(unittest.TestCase):
maxDiff = None

@unittest.expectedFailure # TODO: RUSTPYTHON
@force_not_colorized
def test_range_of_offsets(self):
cases = [
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_future_stmt/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def test_unicode_literals_exec(self):
exec("from __future__ import unicode_literals; x = ''", {}, scope)
self.assertIsInstance(scope["x"], str)

# TODO: RUSTPYTHON; barry_as_FLUFL (<> operator) not supported
@unittest.expectedFailure
def test_syntactical_future_repl(self):
p = spawn_python('-i')
p.stdin.write(b"from __future__ import barry_as_FLUFL\n")
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def test_ellipsis(self):
self.assertTrue(x is Ellipsis)
self.assertRaises(SyntaxError, eval, ".. .")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_eof_error(self):
samples = ("def foo(", "\ndef foo(", "def foo(\n")
for s in samples:
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ def test_stack(self):
self.assertIn('inspect.stack()', record.code_context[0])
self.assertEqual(record.index, 0)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_trace(self):
self.assertEqual(len(git.tr), 3)
frame1, frame2, frame3, = git.tr
Expand Down
12 changes: 0 additions & 12 deletions Lib/test/test_named_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,24 @@ def test_named_expression_invalid_06(self):
with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_07(self):
code = """def spam(a = b := 42): pass"""

with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_08(self):
code = """def spam(a: b := 42 = 5): pass"""

with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_09(self):
code = """spam(a=b := 'c')"""

with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_10(self):
code = """spam(x = y := f(x))"""

Expand Down Expand Up @@ -103,8 +95,6 @@ def test_named_expression_invalid_13(self):
"positional argument follows keyword argument"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_14(self):
code = """(x := lambda: y := 1)"""

Expand All @@ -120,8 +110,6 @@ def test_named_expression_invalid_15(self):
"cannot use assignment expressions with lambda"):
exec(code, {}, {})

# TODO: RUSTPYTHON: wrong error message
@unittest.expectedFailure
def test_named_expression_invalid_16(self):
code = "[i + 1 for i in i := [1,2]]"

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,6 @@ def test_expression_with_assignment(self):
offset=7
)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_curly_brace_after_primary_raises_immediately(self):
self._check_error("f{}", "invalid syntax", mode="single")

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def test_original_excepthook(self):

self.assertRaises(TypeError, sys.__excepthook__)

@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError formatting in arbitrary tracebacks
@force_not_colorized
def test_excepthook_bytes_filename(self):
# bpo-37467: sys.excepthook() must not crash if a filename
Expand Down
Loading
Loading