GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Unexpected behavior with dataclasses and weakref · Issue #102069 · python/cpython Closed Labels 3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionWe recently discovered the following error in our project: 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: import dataclasses import weakref @dataclasses.dataclass(slots=True, weakref_slot=True) class EntityAsDataclass: x: int = 10 class Entity: __slots__ = ("x", "__weakref__") def __init__(self, x: int = 10) -> None: self.x = x e1 = Entity() e1_ref = weakref.ref(e1) e2 = EntityAsDataclass() e2_ref = weakref.ref(e2) assert e1.__weakref__ is e1_ref # works assert e2.__weakref__ is e2_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 PRsActivity
MetadataMetadataAssigneesLabels3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |