Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unexpected behavior with dataclasses and weakref #102069

Closed
Assignees
sobolevn
Labels
3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@jbaudisch

Description

@jbaudisch

We recently discovered the following error in our project:
TypeError: descriptor '__weakref__' for 'XYZ' objects doesn't apply to a 'XYZ' object

XYZ in our case is a dataclass which uses slots (added v3.10) and weakref_slot (added v3.11) parameters.

We further investigated the error and have come to the following example to reproduce it:

importdataclassesimportweakref@dataclasses.dataclass(slots=True,weakref_slot=True)classEntityAsDataclass:x:int=10classEntity:__slots__= ("x","__weakref__")def__init__(self,x:int=10)->None:self.x=xe1=Entity()e1_ref=weakref.ref(e1)e2=EntityAsDataclass()e2_ref=weakref.ref(e2)asserte1.__weakref__ise1_ref# worksasserte2.__weakref__ise2_ref# fails with "TypeError: descriptor '__weakref__' for 'EntityAsDataclass' objects doesn't apply to a 'EntityAsDataclass' object"

I don't know if this is intended, but we expect EntityAsDataclass and Entity to have the same behavior here.

Thanks!

Linked PRs

Metadata

Metadata

Assignees

Labels

3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp