Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dis._try_compile: traceback printed on error in source argument is too wordy #102114

Closed
chgnrdv opened this issue Feb 21, 2023 · 0 comments · Fixed by #102115
Closed

dis._try_compile: traceback printed on error in source argument is too wordy #102114

chgnrdv opened this issue Feb 21, 2023 · 0 comments · Fixed by #102115
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented Feb 21, 2023

_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 (most recent call last):
  File "/home/.../cpython/Lib/dis.py", line 67, in _try_compile
    c = compile(source, name, 'eval')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<dis>", line 1
    )
    ^
SyntaxError: unmatched ')'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.../cpython/Lib/dis.py", line 112, in dis
    _disassemble_str(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive)
  File "/home/.../cpython/Lib/dis.py", line 593, in _disassemble_str
    _disassemble_recursive(_try_compile(source, '<dis>'), **kwargs)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../cpython/Lib/dis.py", line 69, in _try_compile
    c = compile(source, name, 'exec')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<dis>", line 1
    )
    ^
SyntaxError: unmatched ')'

Python versions affected: 3.10.8, 3.11.0, current main.

Linked PRs

@chgnrdv chgnrdv added the type-bug An unexpected behavior, bug, or error label Feb 21, 2023
@chgnrdv chgnrdv changed the title dis._try_compile: traceback printed on error in source code is too wordy dis._try_compile: traceback printed on error in source argument is too wordy Feb 21, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Feb 21, 2023
@iritkatriel iritkatriel added type-feature A feature request or enhancement 3.12 bugs and security fixes and removed type-bug An unexpected behavior, bug, or error labels Apr 6, 2023
ishaiv28 added a commit to ishaiv28/cpython that referenced this issue Apr 15, 2023
pythongh-102114: Make dis print more concise tracebacks for syntax errors i…
carljm added a commit to carljm/cpython that referenced this issue Apr 17, 2023
* main:
  Remove `expert-*` from `project-updater` GH workflow (python#103579)
  pythongh-103583: Add codecs and maps to _codecs_* module state (python#103540)
  pythongh-48330: address review comments to PR-12271 (python#103209)
  pythongh-103527: Add multibytecodec.h as make dep for _codecs_* (python#103567)
  pythongh-103553: Improve `test_inspect`: add more assertions, remove unused (python#103554)
  pythonGH-103517: Improve tests for `pathlib.Path.walk()` (pythonGH-103518)
  pythongh-102114: Make dis print more concise tracebacks for syntax errors in str inputs (python#102115)
  pythonGH-78079: Fix UNC device path root normalization in pathlib (pythonGH-102003)
  pythongh-101517: Add regression test for a lineno bug in try/except* impacting pdb (python#103547)
  pythongh-103527: Add make deps for _codecs_* and _multibytecodec (python#103528)
  pythongh-103532: Fix reST syntax in NEWS entry (pythonGH-103544)
  pythongh-103532: Add NEWS entry (python#103542)
carljm added a commit to carljm/cpython that referenced this issue Apr 17, 2023
* superopt:
  update generated cases with new comment
  review comments
  Remove `expert-*` from `project-updater` GH workflow (python#103579)
  pythongh-103583: Add codecs and maps to _codecs_* module state (python#103540)
  pythongh-48330: address review comments to PR-12271 (python#103209)
  pythongh-103527: Add multibytecodec.h as make dep for _codecs_* (python#103567)
  pythongh-103553: Improve `test_inspect`: add more assertions, remove unused (python#103554)
  pythonGH-103517: Improve tests for `pathlib.Path.walk()` (pythonGH-103518)
  pythongh-102114: Make dis print more concise tracebacks for syntax errors in str inputs (python#102115)
  pythonGH-78079: Fix UNC device path root normalization in pathlib (pythonGH-102003)
  pythongh-101517: Add regression test for a lineno bug in try/except* impacting pdb (python#103547)
  pythongh-103527: Add make deps for _codecs_* and _multibytecodec (python#103528)
  pythongh-103532: Fix reST syntax in NEWS entry (pythonGH-103544)
  pythongh-103532: Add NEWS entry (python#103542)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants