[New-bugs-announce] [issue40796] dataclasses.make_dataclass: Exception when called with different field orders
Darrick Yee
report at bugs.python.org
Wed May 27 13:23:17 EDT 2020
New submission from Darrick Yee <darrick.yee at gmail.com>:
https://docs.python.org/3/library/dataclasses.html#module-dataclasses
`make_dataclass` takes a `field` parameter, which is an iterable whose entries may be tuples of `(name, type)` or `(name, type, dataclasses.Field)`. However, an exception is thrown if such tuples are provided in a particular order. Example:
from dataclasses import field, make_dataclass
fieldspec1 = ('field1', str)
fieldspec2 = ('field2', str, field(default='Hello'))
MyDc1 = make_dataclass('MyDc1', [fieldspec1, fieldspec2]) # Ok
MyDc2 = make_dataclass('MyDc2', [fieldspec2, fieldspec1]) # TypeError
I am guessing this is not intentional...
----------
messages: 370112
nosy: Darrick Yee
priority: normal
severity: normal
status: open
title: dataclasses.make_dataclass: Exception when called with different field orders
type: behavior
versions: Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40796>
_______________________________________
More information about the New-bugs-announce
mailing list