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 — Classes and instances produced by `dataclasses.make_dataclass` are not pickleable · Issue #102103 · python/cpython Closed Closed Copy link Labels stdlibStandard 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 DescriptionRepro: ## Setup >>> import pickle >>> import dataclasses >>> A = dataclasses.make_dataclass('A', []) >>> @dataclasses.dataclass ... class B: pass ... ## Correct >>> pickle.loads(pickle.dumps(B)) <class '__main__.B'> >>> pickle.loads(pickle.dumps(B())) B() ## Wrong >>> pickle.load(pickle.dump(A)) Traceback (most recent call last): File "<stdin>", line 1, in <module> _pickle.PicklingError: Can't pickle <class 'types.A'>: attribute lookup A on types failed >>> pickle.loads(pickle.dumps(A())) Traceback (most recent call last): File "<stdin>", line 1, in <module> _pickle.PicklingError: Can't pickle <class 'types.A'>: attribute lookup A on types failed I think that this happens because of this: >>> A.__module__ 'types' >>> B.__module__ '__main__' After a manual fix it works as it should: >>> A.__module__ = '__main__' >>> pickle.loads(pickle.dumps(A())) A() So, I propose to do it for all dataclasses that we create in I have a simple PR ready, it is inspired by Linked PRsReacted by Alexander Tikhonov Activity
MetadataMetadataAssigneesLabelsstdlibStandard 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. |