This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: PEP 626 does not specify behavior of tracing for keywords.
Type: Stage: resolved
Components: Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, nedbat, pablogsal
Priority: normal Keywords:

Created on 2020-11-16 15:30 by Mark.Shannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg381114 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-11-16 15:30
PEP 626 doesn't cover which keywords are to be traced if they occur on a line by themselves.

Some keywords, like `break`, in Python have behavior associated with them.
Others, like `else` are just syntax and don't do anything.
Currently, it is not clear which keywords get traced and which do not.

I'd like to update the PEP to include the following:

Keywords can be broken down into five groups.
1. Must have an attendant expression ( "if", "while", "for", "await")
   These keywords are not traced, since their expressions are.
2. Have an optional expression and perform non-local control flow ( "return", "yield", "raise", "except" )
   These keywords are traced. If on a different line from the expression, they will generate additional events.
3. Pure syntax ( "else", "try", "finally" )
   These keywords are not traced.
4. Local control flow ( "break", continue", "pass" )
   These keywords are traced
5. Expressions ( "None", "True", "False" )
   Treated like other expressions


1. if (
2.    test
3. ):

will generate an event for line 2.

1. return (
2.    x
3. ):

will generate an event for line 2, then line 1.

1. try:
2.    None
3. finally:
4.    pass

Will generate an event for line 2, then line 4.

Note that whatever changes, the invariant remains that if a line is in `co_lines()` then it will generate trace events, and if it isn't then it won't.
msg381116 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-11-16 16:34
Mark, could you kindly create a proposed update to the PEP in the form of a PR so I can evaluate it and we can iterate directly over the final specification?
msg381679 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-11-23 16:50
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86539
2020-12-05 00:33:08Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: resolved
2020-11-23 16:50:52Mark.Shannonsetmessages: + msg381679
2020-11-16 16:34:44pablogsalsetmessages: + msg381116
2020-11-16 15:30:58Mark.Shannoncreate