Documentation
The current implementation of dataclass modifies a field in place. Thereby, the following code will modify f:
from dataclasses import dataclass, field
f = field(kw_only=True)
@dataclass
class A:
x: int = f
y: int = f
print(f) # now f.name is filled
# furthermore, A is broken (or does not behave if we used two different field instance)
It can create issues when we have multiple fields that have the same spec and we reuse the same Field instance to set the same metadata to all of them. A class is created but it's garbage.
IMHO, in the docs, we should warn the user to NOT share any Field instance.
Linked PRs
Documentation
The current implementation of
dataclassmodifies a field in place. Thereby, the following code will modifyf:It can create issues when we have multiple fields that have the same spec and we reuse the same
Fieldinstance to set the same metadata to all of them. A class is created but it's garbage.IMHO, in the docs, we should warn the user to NOT share any
Fieldinstance.Linked PRs