New submission from Veith Röthlingshöfer <veit...@gmail.com>: 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__. ---------- components: C API messages: 358562 nosy: RunOrVeith priority: normal severity: normal status: open title: __function.__defaults__ breaks for __init__ of dataclasses with default factory type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39078> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com