Skip to content
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

dataclasses: 3.12.3 regression with weakref_slot #118033

Closed
francis-clairicia opened this issue Apr 18, 2024 · 4 comments
Closed

dataclasses: 3.12.3 regression with weakref_slot #118033

francis-clairicia opened this issue Apr 18, 2024 · 4 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@francis-clairicia
Copy link

francis-clairicia commented Apr 18, 2024

Bug report

Bug description:

The __weakref__ slot is not set for classes that have a Generic[T] base.

from typing import Generic, TypeVar
from dataclasses import dataclass

T = TypeVar("T")

@dataclass(slots=True, weakref_slot=True)
class Token(Generic[T]):
    ctx: T

print(f"{Token.__slots__=!r}")
print(f"{hasattr(Token, '__weakref__')=}")

Output on 3.12.2:

Token.__slots__=('ctx', '__weakref__')
hasattr(Token, '__weakref__')=True

On 3.12.3:

Token.__slots__=('ctx',)
hasattr(Token, '__weakref__')=False

CPython versions tested on:

3.12

Operating systems tested on:

Linux, macOS, Windows

Linked PRs

@francis-clairicia francis-clairicia added the type-bug An unexpected behavior, bug, or error label Apr 18, 2024
@Eclips4 Eclips4 added stdlib Python modules in the Lib dir 3.13 bugs and security fixes 3.12 bugs and security fixes labels Apr 18, 2024
@Eclips4
Copy link
Member

Eclips4 commented Apr 18, 2024

Bisected to a22d05f.

@sobolevn
Copy link
Member

Looks like that we need to check __weakref__offset__, then we can decide whether this type has __weakref__ slot or not.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 9, 2024
…ythonGH-118099)

(cherry picked from commit fa9b9cb)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 9, 2024
…ythonGH-118099)

(cherry picked from commit fa9b9cb)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this issue May 9, 2024
…H-118099) (#118821)

gh-118033: Fix `__weakref__` not set for generic dataclasses (GH-118099)
(cherry picked from commit fa9b9cb)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this issue May 9, 2024
…H-118099) (#118822)

gh-118033: Fix `__weakref__` not set for generic dataclasses (GH-118099)
(cherry picked from commit fa9b9cb)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@sobolevn
Copy link
Member

sobolevn commented May 9, 2024

Let's close this issue. I opened a new one for @carljm's suggestion about __slots__ on C types. See #118099 (comment)

@sobolevn sobolevn closed this as completed May 9, 2024
@sobolevn
Copy link
Member

sobolevn commented May 9, 2024

#118829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 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