问题
I have a callable class with @dataclass
annotation.
I want to document it the way, so in the documentation, people can distinguish difference between __call__
and __init__
methods. Since I am using @dataclass
__init__
is automatically generated.
Example of the code in my case:
@final
@dataclass(frozen=True, slots=True)
class Casting(object):
"""Cast one type of code to another.
Constructor arguments:
:param int_converter_function: function to convert to int
:param float_converter_function: function to convert to float
Callable arguments:
:param casting: :term:`casting` object
:type casting: dict
:param value_to_cast: input value
:return: Casted value
Example
>>> cast = Casting(int)
>>> cast({'type': 'integer'}, '123')
123
>>> cast({'type': 'decimal'}, '123.12')
Decimal('123.12')
"""
_int_converter_function = int
_float_converter_function = float
def __call__(self, casting, value_to_cast):
if casting['type'] == 'integer':
return self._int_converter_function(value_to_cast)
return self._float_converter_function(value_to_cast)
I searched for the possible examples but couldn't find anything similar to the above case. The documentation above is hard to read and meshed into a single batch. How can it be done differently so the reader can distinguish the difference between __init__
and __call__
methods from docs?
来源:https://stackoverflow.com/questions/59752572/how-to-document-callable-class-with-sphinx