autoDocstring
autoDocstring copied to clipboard
Incorrect usage of "optional" in argument type
When writing the following function
def my_function(arg: int = 3) -> int:
return arg
autoDocstring generates the following docstring automatically (using Google style docstrings):
def my_function(arg: int = 3) -> int:
"""
[summary]
Args:
arg (int, optional): [description]. Defaults to 3.
Returns:
int: [description]
"""
return arg
The type for arg
is incorrect. It is not optional. Optional does not mean there is a default value. Optional means the argument can also be None. So if the type of arg
is (int, optional)
, then the corresponding type hint would have to be Optional[int]
or Union[int, None]
, which is not the case here.
See https://docs.python.org/3/library/typing.html#special-forms for more info. (Look for Optional right below.)
Ps: I'm using v0.4.1 on vscode. (Which vscode is somehow assuring me is the latest version.)
Yes I always have this issue and would be great to see it fixed! 😄
As @willemvdb42 mentions the (<type>, optional)
in the google docstring style examples is because the param is either None or the other type, not that it has a default (although often None is used as a default arg).
I use the darglint tool to detect discrepancies between the type hints and the docstring and I always have to fix this error manually:
Perhaps this is a different issue, but Optional[str] = None
also becomes (Optional[str], optional)
- I guess it is redundant
Perhaps this is a different issue, but
Optional[str] = None
also becomes(Optional[str], optional)
- I guess it is redundant
I am having the same issue, responding to the thread to ensure it stays open.
Still same issue here with latest autodocstring + darglint2.