mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
gh-102114: Make dis print more concise tracebacks for syntax errors in str inputs (#102115)
This commit is contained in:
parent
8af8f52d17
commit
2b6f5c3483
3 changed files with 11 additions and 3 deletions
|
@ -64,10 +64,10 @@ def _try_compile(source, name):
|
||||||
expect code objects
|
expect code objects
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
c = compile(source, name, 'eval')
|
return compile(source, name, 'eval')
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
c = compile(source, name, 'exec')
|
pass
|
||||||
return c
|
return compile(source, name, 'exec')
|
||||||
|
|
||||||
def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False):
|
def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False):
|
||||||
"""Disassemble classes, methods, functions, and other compiled objects.
|
"""Disassemble classes, methods, functions, and other compiled objects.
|
||||||
|
|
|
@ -1067,6 +1067,13 @@ class DisTests(DisTestBase):
|
||||||
check(dis_nested_2, depth=None)
|
check(dis_nested_2, depth=None)
|
||||||
check(dis_nested_2)
|
check(dis_nested_2)
|
||||||
|
|
||||||
|
def test__try_compile_no_context_exc_on_error(self):
|
||||||
|
# see gh-102114
|
||||||
|
try:
|
||||||
|
dis._try_compile(")", "")
|
||||||
|
except Exception as e:
|
||||||
|
self.assertIsNone(e.__context__)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def code_quicken(f, times=ADAPTIVE_WARMUP_DELAY):
|
def code_quicken(f, times=ADAPTIVE_WARMUP_DELAY):
|
||||||
for _ in range(times):
|
for _ in range(times):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Functions in the :mod:`dis` module that accept a source code string as argument now print a more concise traceback when the string contains a syntax or indentation error.
|
Loading…
Add table
Add a link
Reference in a new issue