-
Notifications
You must be signed in to change notification settings - Fork 41
False Positive for DAR103 with optional arguments #123
Comments
Darglint no longer supports that type format. See issues #114, #112, and #95. The main part of the problem is that each docstring style (Google, Sphinx, Numpy, etc.) introduces different styles for these types. And none of the styles are actually capable of correctly describing all types. (Consider a list of optional strings. With type hints, it would be Instead, Darglint accepts the same type signature accepted by Python type hints. So instead of We could probably parse these informal type descriptions, but it would be a good deal of work without much benefit. (Since type hints have been introduced.) If you'd like to take a crack at it, feel free to open a pull request. As it stands, it's pretty low priority for me. |
Thanks for the explanation @terrencepreilly, that makes sense & is much more complex than it seems on the surface. |
@terrencepreilly I am running across this issue now and am wondering if there are any other solutions? I understand why
It seems to me that if one never intends to allow for |
The selection you quoted isn't saying that optional isn't required if there is a default value. It's saying that if a default value is given, we don't have to use optional type because an unspecified value takes the value given as the default. Sorry if that's confusing. I'm not sure that I'm explaining it in an understandable fashion. Maybe giving an example will clarify things? Say we have a function,
The documentation you quoted is saying that we don't have to type the argument It's pretty confusing. In any case the above type signature is correct. It's communicating that we don't expect the value I closed this issue not because I'm doing any type checking in Darglint. Rather, I'm just deferring to the default Python type hints. It makes it easier for me, and avoids a lot of ambiguity present in some of the type comments present in documentation formats before type hints were introduced. As usual, gradual typing leads to a lot more confusion, even while reducing ambiguity (kind of a conundrum.) |
@terrencepreilly Ah, sorry, I think maybe I didn't fully explain the issue. It's possible I am doing something wrong, but what I am running into is that the following generates an error with def my_func(
arg1: int = 60,
) -> None:
"""Test darglint handling param with default.
Parameters
----------
arg1 : int, default=60
Test default param.
"""
pass
The only solution that I have found is to use Edit: I suppose another option would be to remove the |
Is it possible to make another It's a level of messiness in |
I would strongly, strongly endorse @hectormz point here. Love darglint, but 85% of the errors are false positives with the "optional" flag. |
Running into the same issue here.
|
It appears that optional arguments are generating a false positive alert on DAR103. For example, this function:
generates:
I think this is a repeat of #1 but as that issue was closed, I've created a new one.
The text was updated successfully, but these errors were encountered: