-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
bpo-46244: Remove __slots__ from typing.TypeVar, .ParamSpec #30444
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.
LGTM
(We could maybe think about whether it might be good to add __slots__
to some other typing
classes, but that can be left for another PR -- _TypeVarLike
is definitely the most clear-cut)
Whoa. Looking at the diff I realized for the first time that the two subclasses, I'm sure that the Now I wonder if the problem isn't the inverse -- why do the two subclasses have slots? What does that add? |
@gvanrossum I can imagine the I can imagine Possible solutions:
|
Interesting. I admit that when I implemented Digging through commit history tells me that we only added a |
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.
Removing '__dict__'
slot and running tests does not affect their result. All tests pass without it. It is also not documented.
I also cannot recall any real-life use-case where T.some_attr
is used 🤔
I think that removing __dict__
from __slots__
might be a good idea in the long run.
@sobolevn I'm inclined to agree, although adding |
I'd be very reluctant to remove the I suppose we could ask @serhiy-storchaka if he recalls why he added the It's possible that there's a space-saving reason for having I used to just know this kind of stuff, but the code is a lot more convoluted now due to key-sharing (the dict keys are stored, once, on the class object, and the instances only have a values array), and is about to become more so -- for 3.11 Mark Shannon has improvements that store the values array in a more compact form (IIRC without holes). Anyway, I think the sensible solution is to remove the |
@ariebovenberg is right,
There was no conflict for |
@serhiy-storchaka What do you think of just getting rid of the slots for TypeVar and ParamSpec? |
I am fine with this. |
@serhiy-storchaka @gvanrossum about the slots on If its purpose would be a general mixin, |
Indeed.
It is not. |
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.
LG, but please add a brief blurb.
@@ -0,0 +1,2 @@ | |||
Removed ``__slots__`` from :class:``typing.ParamSpec`` and :class:``typing.TypeVar``. |
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.
Removed ``__slots__`` from :class:``typing.ParamSpec`` and :class:``typing.TypeVar``. | |
Removed ``__slots__`` from :class:`typing.ParamSpec` and :class:`typing.TypeVar`. |
rst uses single backticks.
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.
whoops! Committed the fix below ✅
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.
Thanks all! Landing now.
Should we bother backporting? It doesn't make a difference, so probably not.
@Fidget-Spinner Do you want to land this? Make sure to edit the commit title and message so they match what's ultimately done. |
@Fidget-Spinner: Please replace |
@gvanrossum Sorry, I didn't realize that GH mobile app's squash and merge doesn't allow me to edit the message. After pressing the button it just merged it without prompting me for anything 😞. Lesson learnt: always do the major things on the computer. I'll revert and redo the message later today. Anyways, @ariebovenberg thanks for the patch, and congrats on your first contribution to CPython! |
Their mobile website allows it though. :-)
I wouldn't bother. The summary line is correct: "Remove slots from typing.TypeVar, .ParamSpec ". The commit body is spammy, but that doesn't matter enough to revert and fix the commit. We can live with this!
Indeed. |
The mixin class "typing._TypeVarLike" has no
__slots__
. Its subclasses do define__slots__
, so it looks like a mistake.This was confirmed in the bug report
https://bugs.python.org/issue46244