This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author RunOrVeith
Recipients RunOrVeith
Date 2019-12-17.17:51:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576605114.21.0.115662739436.issue39078@roundup.psfhosted.org>
In-reply-to
Content
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__.
History
Date User Action Args
2019-12-17 17:51:54RunOrVeithsetrecipients: + RunOrVeith
2019-12-17 17:51:54RunOrVeithsetmessageid: <1576605114.21.0.115662739436.issue39078@roundup.psfhosted.org>
2019-12-17 17:51:54RunOrVeithlinkissue39078 messages
2019-12-17 17:51:54RunOrVeithcreate