classification
Title: Tracing events anomaly when creating a multi-line list
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: fabioz, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-10-17 14:53 by fabioz, last changed 2019-10-17 15:48 by fabioz. This issue is now closed.

Files
File name Uploaded Description Edit
snippet33.py fabioz, 2019-10-17 14:53
Messages (3)
msg354845 - (view) Author: Fabio Zadrozny (fabioz) * Date: 2019-10-17 14:53
When creating a multi-line list it seems that there's an additional line event that goes back to the start of the list.

i.e.: considering the code as:

[
1,
2
]

when stepping through the list, a debugger would get a line event at the `1` then at `2` and then at `['.

I'm attaching a sample code which prints the traced lines, where it's possible to see that there's a line event that goes backward to the list creation there (note that on Python 3.7 there's no line event for the list creation).
msg354847 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-17 15:26
Considering the code as:

x = {
1,
2
}

It first gets constant 1.
Then gets constant 2.
Then build a set.
Then assign it to the variable.

Obviously that the variable is assigned at line 1, so you would get a backward line in any case. The set display is multiline, it occupies lines 1 to 4. What line should be reported? In many cases it is more convenient to take a first line of the multiline expression. If the building a set failed (for example if items are not hashable) you will a line "x = {" in the traceback instead of just "}".

This is not a bug, but a feature. In future perhaps tracing and traceback will get a range instead of a single line for multiline expressions, but it requires significant changes in the code.
msg354850 - (view) Author: Fabio Zadrozny (fabioz) * Date: 2019-10-17 15:48
If it's a feature and not a bug, seems ok to me (I reported mainly because I thought the behavior was odd, but I guess it makes sense).
History
Date User Action Args
2019-10-17 15:48:01fabiozsetstatus: open -> closed
resolution: not a bug
messages: + msg354850

stage: resolved
2019-10-17 15:26:05serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg354847
2019-10-17 14:53:28fabiozcreate