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

IDLE: make use of extended error info. #91312

Open
terryjreedy opened this issue Mar 29, 2022 · 5 comments
Open

IDLE: make use of extended error info. #91312

terryjreedy opened this issue Mar 29, 2022 · 5 comments
Assignees

Comments

@terryjreedy
Copy link
Member

BPO 47156
Nosy @terryjreedy, @aroberge

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/terryjreedy'
closed_at = None
created_at = <Date 2022-03-29.22:10:53.350>
labels = ['expert-IDLE', '3.10', '3.11']
title = 'IDLE: make use of extended SyntaxError info.'
updated_at = <Date 2022-03-30.00:59:30.437>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2022-03-30.00:59:30.437>
actor = 'aroberge'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2022-03-29.22:10:53.350>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 47156
keywords = []
message_count = 2.0
messages = ['416302', '416315']
nosy_count = 2.0
nosy_names = ['terry.reedy', 'aroberge']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'test needed'
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue47156'
versions = ['Python 3.10', 'Python 3.11']

@terryjreedy
Copy link
Member Author

terryjreedy commented Mar 29, 2022

In 3.10 and 3.11:

>>> while s := input.read(MAXBINSIZE):
...     while len(s) < MAXBINSIZE and ns := input.read(MAXBINSIZE-len(s)):
  File "<stdin>", line 2
    while len(s) < MAXBINSIZE and ns := input.read(MAXBINSIZE-len(s)):
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: cannot use assignment expressions with expression

IDLE only colors the 'l' of 'len'; add extended marking.

At least in 3.11, some non-syntax errors have 'fine-grained markings'.

x = {'a': {'b': None}}
x['a']['b']['c']['d'] = 1
print(x['a']['b']['c']['d'])

$ python3.11 test.py
Traceback (most recent call last):
  File "/data/shared/lusers/enneking/test.py", line 4 in <module>
    x['a']['b']['c']['d'] = 1
    ~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable

Adding colors may require monkeypatching method or subclassing class in traceback.py. May have commented on traceback issue or PR. Or perhaps use sys._excepthook instead of current code and replace ~^ with colors as print. Note that present on each of multiple lines.

Would have to decide on how to differentiate ~ context versus ^ error site. Could initially not. Or use color 'diluted' with white or foreground or background or mixture color? (Experiment needed.)

Related: Put interactive SyntaxErrors in box.

EDIT: Anyone really want a log of error that occurred during a session?

Andre Roberge would like the last error accessible

@terryjreedy terryjreedy added 3.10 only security fixes 3.11 only security fixes labels Mar 29, 2022
@terryjreedy terryjreedy self-assigned this Mar 29, 2022
@terryjreedy terryjreedy added topic-IDLE 3.10 only security fixes 3.11 only security fixes labels Mar 29, 2022
@terryjreedy terryjreedy self-assigned this Mar 29, 2022
@aroberge
Copy link
Mannequin

aroberge mannequin commented Mar 30, 2022

(Anyone really want log of error?)

If by this you mean having access to the error from a known place (like sys.last_traceback or something else specific to IDLE but available from a script), then the answer from me is definitely yes.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@terryjreedy terryjreedy changed the title IDLE: make use of extended SyntaxError info. IDLE: make use of extended error info. Oct 27, 2022
@terryjreedy
Copy link
Member Author

I clarified my question above as meaning a (recording) of all errors in a session included in the shell output that can be saved to a file. This would be a different issue. So would accessibility from a script. I don't remember if Mar 29 is before or after I patched run.py to improve this.

@gpshead gpshead added the 3.12 bugs and security fixes label Oct 27, 2022
@jdtsmith
Copy link

jdtsmith commented Aug 6, 2023

Has there been any progress made on making use of 3.11's tb.tb_frame.f_code.co_positions()? It seems a shame to calculate them and carry them around, but then provide no ready means to make use of fine-grained positional information from exceptions in the REPL.

@terryjreedy
Copy link
Member Author

co_positions returns an iterable of source-code positions corresponding to bytecodes. I believe it is used, in the standard exception handler, used by the REPL, to created the position-marking lines I illustrated above. This issue is about changing IDLE to retrieve and make use of this newly available information in its simulated Shell.

@terryjreedy terryjreedy removed 3.11 only security fixes 3.10 only security fixes 3.12 bugs and security fixes labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants