Skip to content

dataclasses: implicitly defined __dict__ and __weakref__ slots of inherited classes are ignored. #105866

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

Closed
avboag opened this issue Jun 16, 2023 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@avboag
Copy link
Contributor

avboag commented Jun 16, 2023

Bug report

The weakref slot is redefined when inherited from a class which didn't specify slots at all (and thus has a dict and weakref slots).

from dataclasses import dataclass

class A:
    pass

@dataclass(slots=True, weakref_slot=True)
class B(A):
    pass

gives the following error:

TypeError: __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0

Linked PRs

@avboag avboag added the type-bug An unexpected behavior, bug, or error label Jun 16, 2023
@JelleZijlstra JelleZijlstra changed the title implicitly defined __dict__ and __weakref__ slots of inherited classes are ignored. dataclasses: implicitly defined __dict__ and __weakref__ slots of inherited classes are ignored. Jun 16, 2023
@avboag
Copy link
Contributor Author

avboag commented Jun 16, 2023

The fix seems to be simple, _get_slots should yield from ('dict', 'weakref') when no slots are defined.

@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 26, 2023
@avboag
Copy link
Contributor Author

avboag commented Mar 8, 2024

ping

carljm added a commit that referenced this issue Mar 19, 2024
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 19, 2024
…thonGH-105870)

(cherry picked from commit a22d05f)

Co-authored-by: Aviel Boag <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 19, 2024
…thonGH-105870)

(cherry picked from commit a22d05f)

Co-authored-by: Aviel Boag <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
ambv pushed a commit that referenced this issue Mar 19, 2024
…H-105870) (GH-116978)

(cherry picked from commit a22d05f)

Co-authored-by: Aviel Boag <[email protected]>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
ambv pushed a commit that referenced this issue Mar 19, 2024
…H-105870) (GH-116979)

(cherry picked from commit a22d05f)

Co-authored-by: Aviel Boag <[email protected]>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
@ambv
Copy link
Contributor

ambv commented Mar 19, 2024

All maint branches merged. Thanks!

@ambv ambv closed this as completed Mar 19, 2024
vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
…thon#105870)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…thon#105870)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…thon#105870)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants