PEP-654: warn that leaf_generator recycles tracebacks#2109
PEP-654: warn that leaf_generator recycles tracebacks#2109iritkatriel merged 2 commits intopython:masterfrom
Conversation
pep-0654.rst
Outdated
| # Note: the traceback segments are shallow-copied | ||
| # into tbs so they can be shared by multiple leaf | ||
| # exceptions. Make a deep copy if your use case | ||
| # requires that. |
There was a problem hiding this comment.
Huh, this is actually ambiguous (I hadn't realized this before): the singly-linked list of Traceback objects is mutable (you could set any item's tb_next and mutate the chain) and in addition the tbs list is reused by each iteration through the generator.
I'm not particularly worried about people mutating the Traceback objects, but somehow your comment appears to refer to them. To describe the reuse of tbs, maybe reformulate the note like this?
Note: the list returned (
tbs) is reused by each iteration through the generator.
Make a copy of your use case holds on to it beyond the current iteration.
There was a problem hiding this comment.
Ah I see, yes. I am a bit concerned also about people concatenating the tb chunks of tbs to make it look like one traceback.
gvanrossum
left a comment
There was a problem hiding this comment.
I wouldn't worry too much about people mutating the linked lists of Traceback objects -- we don't mutate those (even if the traceback is bubbled up, we only append new Traceback objects to the front of the list), so it's a lesser concern than people just storing a reference to the yielded list, which is definitely going to give them a hard-to-debug problem. (We could solve the latter by returning a copy of the list, but that seems unperformant in the common case.)
The common case is you don't iterate at all. I hope nobody will use this function. |
No description provided.