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
Cannot specify weakref_slot=True
twice in dataclass MRO
#93521
Comments
Here's an example of the same thing without dataclasses: class A:
__slots__='__weakref__'
class B(A):
__slots__='__weakref__'
|
I'm not sure this is a bug, just the way things work. |
It would be nice if dataclasses took care of this issue automatically though. Example scenario: I have a library in which I expose a dataclass. A user subclasses my class in another dataclass, and wants to use weakrefs, so they use |
Locally I fixed this already, and I am planning on opening a PR with an added test. Should that PR point to |
main |
…sent in bases (pythonGH-93535) (cherry picked from commit 5849af7) Co-authored-by: Bluenix <bluenixdev@gmail.com>
Summary
If a child dataclass of a parent dataclass who specified
weakref_slot
, also decides to setweakref_slot
to True, Python will raise a TypeError as seen below:Description
I am porting dataclasses' slots and weakref slots kwargs into a decorator I can use. While doing so, I decided to change the default of the
weakref_slot
because I would like all of my classes to be weakref:able. This is when I ran into the issue which can be reproduced by the code below:Environment
This was tested by creating a file named
copyclasses.py
with the current contents ofLib/dataclasses.py
ran using a 3.10 CPython interpreter. Note that I've restored the naming of the module in the codeblock above assuming those who will be running it will have a built 3.11 CPython interpreter.Footnotes: I will mention @ericvsmith as the code owner of the dataclasses file.
The text was updated successfully, but these errors were encountered: