Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
Closed
Description
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 ** 2Runninghelp(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 secondIt 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