Skip to content

Commit 83fdea8

Browse files
authored
add support for typing.overload (#22)
* add support for typing.overload
1 parent 628f301 commit 83fdea8

File tree

6 files changed

+68
-12
lines changed

6 files changed

+68
-12
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
22
"python.analysis.typeCheckingMode": "basic",
3-
"python.linting.pylintEnabled": true,
4-
"python.linting.enabled": true,
5-
"python.formatting.provider": "black"
63
}

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
## [v1.3.0] - 2023-11-29
6+
7+
### Added
8+
9+
- Support for `typing.overload`.
10+
511
## [v1.2.0] - 2023-07-12
612

713
### Added
@@ -110,3 +116,4 @@
110116
[v1.0.4]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.4
111117
[v1.1.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.1.0
112118
[v1.2.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.2.0
119+
[v1.3.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.3.0

flake8_docstrings_complete/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,30 @@ def _is_fixture_decorator(self, node: ast.expr) -> bool:
295295
# No valid syntax can reach here
296296
return False # pragma: nocover
297297

298+
def _is_overload_decorator(self, node: ast.expr) -> bool:
299+
"""Determine whether an expression is an overload decorator.
300+
301+
Args:
302+
node: The node to check.
303+
304+
Returns:
305+
Whether the node is an overload decorator.
306+
"""
307+
if isinstance(node, ast.Name):
308+
return node.id == "overload"
309+
310+
# Handle call
311+
if isinstance(node, ast.Call):
312+
return self._is_overload_decorator(node=node.func)
313+
314+
# Handle attr
315+
if isinstance(node, ast.Attribute):
316+
value = node.value
317+
return node.attr == "overload" and isinstance(value, ast.Name) and value.id == "typing"
318+
319+
# There is no valid syntax that gets to here
320+
return False # pragma: nocover
321+
298322
def _skip_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
299323
"""Check whether to skip a function.
300324
@@ -321,6 +345,10 @@ def _skip_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
321345
if self._file_type in {types_.FileType.TEST, types_.FileType.FIXTURE}:
322346
return any(self._is_fixture_decorator(decorator) for decorator in node.decorator_list)
323347

348+
# Check for overload
349+
if any(self._is_overload_decorator(decorator) for decorator in node.decorator_list):
350+
return True
351+
324352
return False
325353

326354
def visit_any_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:

flake8_docstrings_complete/attrs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""The arguments section checks."""
1+
"""The attributes section checks."""
22

33
from __future__ import annotations
44

pyproject.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
[tool.poetry]
22
name = "flake8-docstrings-complete"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
description = "A linter that checks docstrings are complete"
55
authors = ["David Andersson <[email protected]>"]
66
license = "Apache 2.0"
77
readme = "README.md"
8-
packages = [{include = "flake8_docstrings_complete"}]
8+
packages = [{ include = "flake8_docstrings_complete" }]
99
classifiers = [
1010
"Framework :: Flake8",
1111
"Environment :: Console",
1212
"Intended Audience :: Developers",
1313
"License :: OSI Approved :: Apache Software License",
1414
"Programming Language :: Python",
1515
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3.12",
1617
"Programming Language :: Python :: 3.11",
1718
"Programming Language :: Python :: 3.10",
1819
"Programming Language :: Python :: 3.9",
@@ -57,9 +58,5 @@ module = "tests.*"
5758
disallow_untyped_defs = false
5859

5960
[tool.pylint.messages_control]
60-
enable = [
61-
"useless-suppression"
62-
]
63-
disable = [
64-
"wrong-import-position"
65-
]
61+
enable = ["useless-suppression"]
62+
disable = ["wrong-import-position"]

tests/unit/test___init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,33 @@ def function_1():
3131
),
3232
pytest.param(
3333
"""
34+
@overload
35+
def function_1():
36+
...
37+
""",
38+
(),
39+
id="function docstring missing overload",
40+
),
41+
pytest.param(
42+
"""
43+
@overload()
44+
def function_1():
45+
...
46+
""",
47+
(),
48+
id="function docstring missing overload call",
49+
),
50+
pytest.param(
51+
"""
52+
@typing.overload
53+
def function_1():
54+
...
55+
""",
56+
(),
57+
id="function docstring missing overload attr",
58+
),
59+
pytest.param(
60+
"""
3461
def function_1():
3562
return
3663

0 commit comments

Comments
 (0)