Message358562
When creating a dataclass with a default that is a field with a default factory, the factory is not correctly resolved in cls.__init__.__defaults__. It evaluates to the __repr__ of dataclasses._HAS_DEFAULT_FACTORY_CLASS, which is "<factory>".
The expected behavior would be to have a value of whatever the default factory produces as a default.
This causes issues for example when using inspect.BoundParameters.apply_defaults() on the __init__ of such a dataclass.
Code to reproduce:
```
from dataclasses import dataclass, field
from typing import Any, Dict
@dataclass()
class Test:
a: int
b: Dict[Any, Any] = field(default_factory=dict)
print(Test.__init__.__defaults__) # <factory>
```
The affected packages are on a high-level dataclasses, on a lower level the issue is in the builtin __function.__defaults__. |
|
Date |
User |
Action |
Args |
2019-12-17 17:51:54 | RunOrVeith | set | recipients:
+ RunOrVeith |
2019-12-17 17:51:54 | RunOrVeith | set | messageid: <1576605114.21.0.115662739436.issue39078@roundup.psfhosted.org> |
2019-12-17 17:51:54 | RunOrVeith | link | issue39078 messages |
2019-12-17 17:51:54 | RunOrVeith | create | |
|