You can't do this for types like str, int, float etc.
You can make a doctstring for functions, methods and properties.
class Foo:
"""
This is a dummy class. Nothing special going on here.
"""
def __init__(self, name):
"""
Method to initialize the class. Only the name is needed.
"""
self.name = name
@property
def hello_property(self):
"""
This property returns a greeting
"""
return f'Hello {self.name}'
def hello_method(self):
"""
Hello Method returns a greeting
"""
help(Foo)
Output:
Help on class Foo in module __main__:
class Foo(builtins.object)
| Foo(name)
|
| Methods defined here:
|
| __init__(self, name)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| hello
| This property returns a greeting
(END)
If you use for example enum, you can document your code with names.
import enum
class Color(enum.IntEnum):
red = 0
green = 1
blue = 2
help(Color)
Output:
Help on class Color in module __main__:
class Color(enum.IntEnum)
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
|
| An enumeration.
|
| Method resolution order:
| Color
| enum.IntEnum
| builtins.int
| enum.Enum
| builtins.object
|
| Data and other attributes defined here:
|
| blue = <Color.blue: 2>
|
| green = <Color.green: 1>
|
| red = <Color.red: 0>
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.EnumMeta:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
If you go further, you could use type hinting, which is good for IDEs.
def calc_delta_range(bandwidth: int) -> float:
"""
Calculate the delta range of a K-MD2
bandwidth := frequency in MHz
returns := delta range in meter
"""
return 150e6 * (257 / (256 * bandwidth * 1e6))
help(calc_delta_range)
Output:
Help on function calc_delta_range in module __main__:
calc_delta_range(bandwidth: int) -> float
Calculate the delta range of a K-MD2
bandwidth := frequency in MHz
returns := delta range in meter
(END)