-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Open
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Related: huggingface/transformers#8978
import collections
import copy
import dataclasses
@dataclasses.dataclass
class ModelOutputDictBase(dict):
a: int
b: int = 2
# works
copy.deepcopy(
ModelOutputDictBase(
a=1,
b=2,
)
)
@dataclasses.dataclass
class ModelOutputAllDefaults(collections.OrderedDict):
a: int = 1
b: int = 2
# works
copy.deepcopy(
ModelOutputAllDefaults(
a=1,
b=2,
)
)
@dataclasses.dataclass
class ModelOutput(collections.OrderedDict):
a: int
b: int = 2
# fails
copy.deepcopy(
ModelOutput(
a=1,
b=2,
)
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 39
35 a: int
36 b: int = 2
---> 39 copy.deepcopy(
40 ModelOutput(
41 a=1,
42 b=2,
43 )
44 )
File [...lib/python3.8/copy.py:172), in deepcopy(x, memo, _nil)
170 y = x
171 else:
--> 172 y = _reconstruct(x, memo, *rv)
174 # If is its own copy, don't memoize.
175 if y is not x:
File [.../lib/python3.8/copy.py:264), in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
262 if deep and args:
263 args = (deepcopy(arg, memo) for arg in args)
--> 264 y = func(*args)
265 if deep:
266 memo[id(x)] = y
TypeError: __init__() missing 1 required positional argument: 'a'
Your environment
- CPython versions tested on: Python 3.8.16 (default, Jan 17 2023, 23:13:24) [GCC 11.2.0] :: Anaconda, Inc. on linux
- Operating system and architecture: Ubuntu 20.04.6 LTS x86_64
Linked PRs
qthequartermasterman
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error