ericvsmith / dataclasses

Apache License 2.0
584 stars 53 forks source link

[Question] Correct docstring default value using default_factory #162

Closed carmocca closed 3 years ago

carmocca commented 3 years ago

Hi, given this snippet:

import dataclasses
from typing import List

@dataclasses.dataclass
class Foo:
    bar: List[str] = dataclasses.field(default_factory=lambda: ["foo"])

print(Foo.__doc__)

which prints: Foo(bar: List[str] = <factory>)

is there any way to have it be?: Foo(bar: List[str] = ["foo"])

Thanks!

ericvsmith commented 3 years ago

No, there's not. The code would have to inspect the factory function and figure out what it returns, which in general is not possible.