Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions darglint/analysis/argument_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ def add_arg_by_name(self, name, arg):

def visit_arguments(self, node):
# type: (ast.arguments) -> ast.AST
if hasattr(node, 'posonlyargs'):
annotatable_args = [*node.posonlyargs, *node.args]
else:
annotatable_args = node.args
# make args with default values optional
for index, default in enumerate(node.defaults):
if default is not None:
if hasattr(annotatable_args[-index - 1].annotation, 'id'):
if not 'optional' in annotatable_args[-index - 1].annotation.id.lower():
annotatable_args[
-index - 1
].annotation.id = f'{annotatable_args[-index - 1].annotation.id}, optional'

if hasattr(node, 'posonlyargs'):
for arg in node.posonlyargs:
self.add_arg_by_name(arg.arg, arg)
Expand Down