Automatically generates a docstring for type annotated functions
python3 -m types2docstring file.py
Note: this project is still very much a WIP -- so backup all important files before using this tool!!
Starting point:
# should get a docstringdeff(x: int) ->int:
returnx*x# should get a docstringdeff2(x: int, y: int) ->int:
returnx*y# not fully annotated, so should not get a docstringdeff3(x) ->int:
returnx*x# already has a docstring, so should not get a (new) docstring.deff5(x: int) ->int:
"""i am a docstring"""returnx*x# should get a docstringdeftest(
x: int,
y: int,
*,
test: str
) ->int:
iftest=='hi':
returnx*yelse:
returnxifTrue:
# should get a docstring, with correct indentationdefnested(x: int) ->int:
returnx*xRunning python3 -m types2docstring example.py gives:
# should get a docstringdeff(x: int) ->int:
''' [function description] :param x: [x description] :type x: int :returns: [return description] :rtype: int '''returnx*x# should get a docstringdeff2(x: int, y: int) ->int:
''' [function description] :param x: [x description] :type x: int :param y: [y description] :type y: int :returns: [return description] :rtype: int '''returnx*y# not fully annotated, so should not get a docstringdeff3(x) ->int:
returnx*x# already has a docstring, so should not get a (new) docstring.deff5(x: int) ->int:
"""i am a docstring"""returnx*x# should get a docstringdeftest(
x: int,
y: int,
*,
test: str
) ->int:
''' [function description] :param x: [x description] :type x: int :param y: [y description] :type y: int :param test: [test description] :type test: str :returns: [return description] :rtype: int '''iftest=='hi':
returnx*yelse:
returnxifTrue:
# should get a docstring, with correct indentationdefnested(x: int) ->int:
''' [function description] :param x: [x description] :type x: int :returns: [return description] :rtype: int '''returnx*x