-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PEP 678: Clarify how the notes tuple is updated and when it is copied #2377
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment on clarity.
OK, I've pushed a (I sincerely hope it's) final half-sentence specifying that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 = None I'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).