Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support field docstrings for dataclasses that use __slots__ #113878

Closed
Assignees
ericvsmith
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@rhettinger

Description

@rhettinger

Feature or enhancement

Proposal:

A really nice__slots__ feature is the ability to provide a data dictionary in the form of docstrings. That is also available forproperty objects. Consider this example:

class Rocket:    __slots__ = {        'velocity': 'Speed relative to Earth in meters per second',        'mass': 'Gross weight in kilograms',    }    @property    def kinetic_energy(self):        'Kinetic energy in Newtons'        return self.mass * self.velocity ** 2

Runninghelp(Rocket) shows all the field docstrings which is super helpful:

class Rocket(builtins.object) |  Readonly properties defined here: | |  kinetic_energy |      Kinetic energy in Newtons | |  ---------------------------------------------------------------------- |  Data descriptors defined here: | |  mass |      Gross weight in kilograms | |  velocity |      Speed relative to Earth in meters per second

It would be nice is the same can be done with dataclasses that define__slots__:

@dataclass(slots=True)class Rocket:    velocity: float = field(doc='Speed relative to Earth in meters per second')    weight: float = field(doc='Gross weight in kilograms')

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2026 Movatter.jp