Skip to content

Make dataclasses construct automatic docstrings lazily #144764

@adamchainz

Description

@adamchainz

Feature or enhancement

Proposal:

Profiling import time on a client project revealed ~30% of the time for dataclasses was spent creating the docstring, mostly because inspect.signature() is costly. In most executions, this time is wasted, as such automated docstrings are rarely referred to during normal execution.

It’s possible to make the docstring generation lazy by writing a descriptor class.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions