Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Closed
Closed
Copy link
Labels
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
_try_compile function from dis module firstly tries to compile given source string with 'eval' mode and, if exception is occured, catches it and tries again with 'exec' mode. These actions lead to a long chained traceback if given string contains syntax/indentation error, because this string gets refused by compile in both 'eval' and 'exec' modes.
All functions/constructors from dis module that use _try_compile and accept source string as an argument (dis, get_instructions, code_info, show_code, Bytecode) are showing this behavior:
>>>dis.dis(')') Traceback (mostrecentcalllast): File"/home/.../cpython/Lib/dis.py", line67, in_try_compilec=compile(source, name, 'eval') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"<dis>", line1 ) ^SyntaxError: unmatched')'Duringhandlingoftheaboveexception, anotherexceptionoccurred: Traceback (mostrecentcalllast): File"<stdin>", line1, in<module>File"/home/.../cpython/Lib/dis.py", line112, indis_disassemble_str(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive) File"/home/.../cpython/Lib/dis.py", line593, in_disassemble_str_disassemble_recursive(_try_compile(source, '<dis>'), **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/home/.../cpython/Lib/dis.py", line69, in_try_compilec=compile(source, name, 'exec') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"<dis>", line1 ) ^SyntaxError: unmatched')'Python versions affected: 3.10.8, 3.11.0, current main.
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement