From 16d76421f19a37b7bea987c170a7ad943861958e Mon Sep 17 00:00:00 2001 From: David Andersson Date: Thu, 11 Apr 2024 17:42:10 +1000 Subject: [PATCH 1/5] add support for from_exc_data --- .flake8 | 2 +- flake8_docstrings_complete/raises.py | 8 ++++++++ tests/unit/test___init__raises.py | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 5e00723..8f045c4 100644 --- a/.flake8 +++ b/.flake8 @@ -1,7 +1,7 @@ [flake8] max-line-length = 99 max-doc-length = 99 -extend-ignore = E203,W503 +extend-ignore = E203,W503,E231,E201 per-file-ignores = tests/*:D205,D400 flake8_docstrings_complete/*:N802 diff --git a/flake8_docstrings_complete/raises.py b/flake8_docstrings_complete/raises.py index 56efbbe..0f8d0f5 100644 --- a/flake8_docstrings_complete/raises.py +++ b/flake8_docstrings_complete/raises.py @@ -6,6 +6,8 @@ from collections import Counter from typing import Iterable, Iterator +from astpretty import pprint + from . import docstring, types_ from .constants import ERROR_CODE_PREFIX, MORE_INFO_BASE @@ -75,6 +77,12 @@ def _get_exc_node(node: ast.Raise) -> types_.Node | None: col_offset=node.exc.func.col_offset, ) if isinstance(node.exc.func, ast.Attribute): + if node.exc.func.attr == "from_exc_data": + return types_.Node( + name=node.exc.func.value.id, + lineno=node.exc.func.lineno, + col_offset=node.exc.func.col_offset, + ) return types_.Node( name=node.exc.func.attr, lineno=node.exc.func.lineno, diff --git a/tests/unit/test___init__raises.py b/tests/unit/test___init__raises.py index 5fd0cce..78ec788 100644 --- a/tests/unit/test___init__raises.py +++ b/tests/unit/test___init__raises.py @@ -105,6 +105,18 @@ def function_1(): def function_1(): """Docstring 1. + Raises: + """ + raise Exc1.from_exc_data() +''', + (f"7:10 {EXC_NOT_IN_DOCSTR_MSG % 'Exc1'}",), + id="function raises single exc from exc data docstring no exc", + ), + pytest.param( + ''' +def function_1(): + """Docstring 1. + Raises: """ raise Exc1 @@ -493,6 +505,19 @@ def function_1(): ), pytest.param( ''' +def function_1(): + """Docstring 1. + + Raises: + Exc1: + """ + raise Exc1.from_exc_data() +''', + (), + id="function single raise exc docstring raises from exception data", + ), + pytest.param( + ''' def function_1(): """Docstring 1.""" def function_2(): From f5053456e35835d57f8e43040e7da0761fe0f2ff Mon Sep 17 00:00:00 2001 From: David Andersson Date: Thu, 11 Apr 2024 17:43:38 +1000 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eadd307..c006cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [v1.4.0] - 2024-04-11 + +### Added + +- Support for `Exception.from_exc_data`. + ## [v1.3.0] - 2023-11-29 ### Added @@ -117,3 +123,4 @@ [v1.1.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.1.0 [v1.2.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.2.0 [v1.3.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.3.0 +[v1.4.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.4.0 diff --git a/pyproject.toml b/pyproject.toml index e4026e1..5ce5b6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "flake8-docstrings-complete" -version = "1.3.0" +version = "1.4.0" description = "A linter that checks docstrings are complete" authors = ["David Andersson "] license = "Apache 2.0" From d2d669a04ec920ee71b6349f353631adfdcd8182 Mon Sep 17 00:00:00 2001 From: David Andersson Date: Thu, 11 Apr 2024 17:45:43 +1000 Subject: [PATCH 3/5] remove unused import --- flake8_docstrings_complete/raises.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake8_docstrings_complete/raises.py b/flake8_docstrings_complete/raises.py index 0f8d0f5..0d66fe1 100644 --- a/flake8_docstrings_complete/raises.py +++ b/flake8_docstrings_complete/raises.py @@ -6,8 +6,6 @@ from collections import Counter from typing import Iterable, Iterator -from astpretty import pprint - from . import docstring, types_ from .constants import ERROR_CODE_PREFIX, MORE_INFO_BASE From cdac3400a6df5da56961683d0a623612f1d75b2e Mon Sep 17 00:00:00 2001 From: David Andersson Date: Thu, 11 Apr 2024 17:48:08 +1000 Subject: [PATCH 4/5] correct function name --- CHANGELOG.md | 2 +- flake8_docstrings_complete/raises.py | 2 +- tests/unit/test___init__raises.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c006cf3..4ce5d2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Added -- Support for `Exception.from_exc_data`. +- Support for `Exception.from_exception_data`. ## [v1.3.0] - 2023-11-29 diff --git a/flake8_docstrings_complete/raises.py b/flake8_docstrings_complete/raises.py index 0d66fe1..e1a0274 100644 --- a/flake8_docstrings_complete/raises.py +++ b/flake8_docstrings_complete/raises.py @@ -75,7 +75,7 @@ def _get_exc_node(node: ast.Raise) -> types_.Node | None: col_offset=node.exc.func.col_offset, ) if isinstance(node.exc.func, ast.Attribute): - if node.exc.func.attr == "from_exc_data": + if node.exc.func.attr == "from_exception_data": return types_.Node( name=node.exc.func.value.id, lineno=node.exc.func.lineno, diff --git a/tests/unit/test___init__raises.py b/tests/unit/test___init__raises.py index 78ec788..29ebdf4 100644 --- a/tests/unit/test___init__raises.py +++ b/tests/unit/test___init__raises.py @@ -107,7 +107,7 @@ def function_1(): Raises: """ - raise Exc1.from_exc_data() + raise Exc1.from_exception_data() ''', (f"7:10 {EXC_NOT_IN_DOCSTR_MSG % 'Exc1'}",), id="function raises single exc from exc data docstring no exc", @@ -511,7 +511,7 @@ def function_1(): Raises: Exc1: """ - raise Exc1.from_exc_data() + raise Exc1.from_exception_data() ''', (), id="function single raise exc docstring raises from exception data", From 90fa0b303be99a427d4a928167a11afa114b8f49 Mon Sep 17 00:00:00 2001 From: David Andersson Date: Thu, 11 Apr 2024 17:51:16 +1000 Subject: [PATCH 5/5] fix linting --- flake8_docstrings_complete/raises.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake8_docstrings_complete/raises.py b/flake8_docstrings_complete/raises.py index e1a0274..9f6e17c 100644 --- a/flake8_docstrings_complete/raises.py +++ b/flake8_docstrings_complete/raises.py @@ -75,7 +75,10 @@ def _get_exc_node(node: ast.Raise) -> types_.Node | None: col_offset=node.exc.func.col_offset, ) if isinstance(node.exc.func, ast.Attribute): - if node.exc.func.attr == "from_exception_data": + if ( + isinstance(node.exc.func.value, ast.Name) + and node.exc.func.attr == "from_exception_data" + ): return types_.Node( name=node.exc.func.value.id, lineno=node.exc.func.lineno,