-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-135228: Create __dict__ and __weakref__ descriptors for object #136966
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
base: main
Are you sure you want to change the base?
Conversation
…ke the original class collectible An interesting hack, but more localized in scope than python#135230. This may be a breaking change if people intentionally keep the original class around when using `@dataclass(slots=True)`, and then use `__dict__` or `__weakref__` on the original class.
I can polish this, but I think it'd be better to target 3.15, and follow through a bit more. |
Here's a polished version: the descriptors are made for And since they're the same for all objects, they can be shared across all types in an interpreter -- that is, cached in interpreter state. |
Here's another possible way to solve #135228:
The
__dict__
and__weakref__
descriptors don't really need to hold a strong reference to "their" type; they are generic and could be created forobject
instead.Here's a proof of concept. A cleaner way to do this would be creating the descriptor objects once and caching them in the interpreter state.
This does involve a behaviour change -- before:
After: