PEP 678: Clarify how the notes tuple is updated and when it is copied#2377
PEP 678: Clarify how the notes tuple is updated and when it is copied#2377JelleZijlstra merged 6 commits intopython:mainfrom
Conversation
|
OK, I've pushed a (I sincerely hope it's) final half-sentence specifying that |
CAM-Gerlach
left a comment
There was a problem hiding this comment.
Mean to do so earlier, but LGTM from a PEP editor perspective, pending approval by @iritkatriel .
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
|
I'm moving some discussion here since I don't think it belongs in python/steering-council#105 (I don't like having a substantive discussion in the SC tracker). @iritkatriel wrote:
(Note that that is this PR.)
I really want this to grow the size of exception objects by only one pointer. The current formulation (as of this PR) then pretty much forces us into this implementation: class BaseException:
...
__notes: tuple[str, ...] | None = None # Private variable
def add_note(self, note: str):
if self.__notes is None:
self.__notes = (note,)
else:
self.__notes = (*self.__notes__, note)
@property
def __notes__(self) -> tuple[str, ...] | None:
return self.__notes
@__notes__.deleter
def __notes__(self):
self.__notes = NoneI'd wish to allow |
|
@Zac-HD wrote above:
But I'm not sure what this test is or why it's obvious. |
|
If you split an |
|
People shouldn’t compare tuple by identity any more than they should integers. |
|
In that case we can remove the last commit from python/cpython#31317 and then we have the notes in a list and we create a new tuple each time it’s accessed. The pep doesn’t need to say all of this, but to Brett’s point it needs to say that the tuple you got from |
That feels unnecessary. Tuples can't be mutated (unless you do something really crazy in C), so there's no need to spell that out. |
That was my starting point too, but Brett pushed back specifically because "in C you can do anything." So it seems we need to somehow make that clear without forcing an implementation. I personally think it's fine to put notes in a list and tuplify on demand without caching. (But I also think it's fine to put them in a tuple, creating a fresh tuple in add_note().) |
Following python/steering-council#105 (comment).