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

avoid raising DCO010 for overloads #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion flake8_docstrings_complete/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _skip_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
"""Check whether to skip a function.

A function is skipped if it is a test function in a test file, if it is a fixture in a test
or fixture file or if it is a property.
or fixture file, if it is a property or if it is an overload.

Args:
node: The function to check
Expand All @@ -321,6 +321,10 @@ def _skip_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
if self._file_type in {types_.FileType.TEST, types_.FileType.FIXTURE}:
return any(self._is_fixture_decorator(decorator) for decorator in node.decorator_list)

# Check for overload
if any(attrs.is_overload_decorator(decorator) for decorator in node.decorator_list):
return True

return False

def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
Expand Down
25 changes: 25 additions & 0 deletions flake8_docstrings_complete/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ def is_property_decorator(node: ast.expr) -> bool:
return False # pragma: nocover


def is_overload_decorator(node: ast.expr) -> bool:
"""Determine whether an expression is an overload decorator.

Args:
node: The node to check.

Returns:
Whether the node is an overload decorator.
"""
if isinstance(node, ast.Name):
return node.id == "overload"

# Handle call
if isinstance(node, ast.Call):
return is_overload_decorator(node=node.func)

# Handle attr
if isinstance(node, ast.Attribute):
value = node.value
return node.attr == "overload" and isinstance(value, ast.Name) and value.id == "typing"

# There is no valid syntax that gets to here
return False # pragma: nocover


def _get_class_target_name(target: ast.expr) -> ast.Name | None:
"""Get the name of the target for an assignment on the class.

Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,32 @@ class Class1:
"",
id=f"{DUPLICATE_ATTR_CODE} disabled",
),
pytest.param(
"""
from typing import overload


@overload
def foo():
...
""",
"source.py",
"",
id="overload",
),
pytest.param(
"""
import typing


@typing.overload
def foo():
...
""",
"source.py",
"",
id="typing.overload",
),
],
)
def test_pass(code: str, filename: str, extra_args: str, tmp_path: Path):
Expand Down
Loading