Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In linter, ignore @overload functions #562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions numpydoc/hooks/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def name(self) -> str:
def is_function_or_method(self) -> bool:
return isinstance(self.node, (ast.FunctionDef, ast.AsyncFunctionDef))

@property
def is_overload(self) -> bool:
decorators = getattr(self.node, "decorator_list", [])
return any(d.id == "overload" for d in decorators)

@property
def is_generator_function(self) -> bool:
if not self.is_function_or_method:
Expand Down
9 changes: 8 additions & 1 deletion numpydoc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ def type(self):
def is_function_or_method(self):
return inspect.isfunction(self.obj)

@property
def is_overload(self) -> bool:
# Not sure how to figure out when a function is overloaded
# without looking at its AST
return False

@property
def is_generator_function(self):
return inspect.isgeneratorfunction(_unwrap(self.obj))
Expand Down Expand Up @@ -633,7 +639,8 @@ def validate(obj_name, validator_cls=None, **validator_kwargs):

errs = []
if not doc.raw_doc:
if "GL08" not in ignore_validation_comments:
# Check if we are dealing with a `typing.overload` function
if "GL08" not in ignore_validation_comments and not doc.is_overload:
errs.append(error("GL08"))
return {
"type": doc.type,
Expand Down
Loading