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

293 second layer defined functions seem not to be checked #298

Merged
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[Unreleased](https://github.com/jshwi/docsig/compare/v0.46.0...HEAD)
------------------------------------------------------------------------
### Added
- option for checking nested functions and classes

### Fixed
- check indented functions and classes

[0.46.0](https://github.com/jshwi/docsig/releases/tag/v0.46.0) - 2024-04-09
------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Commandline

.. code-block:: console

usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-o] [-p] [-P] [-i] [-a] [-k]
[-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
usage: docsig [-h] [-V] [-l] [-c | -C] [-D] [-m] [-N] [-o] [-p] [-P] [-i] [-a]
[-k] [-n] [-S] [-v] [-s STR] [-d LIST] [-t LIST] [-e EXCLUDE]
[path [path ...]]

Check signature params for proper documentation
Expand All @@ -96,6 +96,7 @@ Commandline
-D, --check-dunders check dunder methods
-m, --check-protected-class-methods check public methods belonging to protected
classes
-N, --check-nested check nested functions and classes
-o, --check-overridden check overridden methods
-p, --check-protected check protected functions and classes
-P, --check-property-returns check property return values
Expand Down
6 changes: 6 additions & 0 deletions docsig/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def _add_arguments(self) -> None:
action="store_true",
help="check public methods belonging to protected classes",
)
self.add_argument(
"-N",
"--check-nested",
action="store_true",
help="check nested functions and classes",
)
self.add_argument(
"-o",
"--check-overridden",
Expand Down
23 changes: 23 additions & 0 deletions docsig/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _run_check( # pylint: disable=too-many-arguments
check_class: bool,
check_class_constructor: bool,
check_dunders: bool,
check_nested: bool,
check_overridden: bool,
check_protected: bool,
check_property_returns: bool,
Expand Down Expand Up @@ -79,6 +80,24 @@ def _run_check( # pylint: disable=too-many-arguments
failures.append(
_Failure(child, _FuncStr(child, no_ansi), report)
)

if check_nested:
for func in child:
_run_check(
func,
child,
check_class,
check_class_constructor,
check_dunders,
check_nested,
check_overridden,
check_protected,
check_property_returns,
ignore_no_params,
no_ansi,
targets,
failures,
)
else:
for func in child:
_run_check(
Expand All @@ -87,6 +106,7 @@ def _run_check( # pylint: disable=too-many-arguments
check_class,
check_class_constructor,
check_dunders,
check_nested,
check_overridden,
check_protected,
check_property_returns,
Expand All @@ -107,6 +127,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
check_class_constructor: bool = False,
check_dunders: bool = False,
check_protected_class_methods: bool = False,
check_nested: bool = False,
check_overridden: bool = False,
check_protected: bool = False,
check_property_returns: bool = False,
Expand Down Expand Up @@ -138,6 +159,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
:param check_dunders: Check dunder methods
:param check_protected_class_methods: Check public methods belonging
to protected classes.
:param check_nested: Check nested functions and classes.
:param check_overridden: Check overridden methods
:param check_protected: Check protected functions and classes.
:param check_property_returns: Run return checks on properties.
Expand Down Expand Up @@ -186,6 +208,7 @@ def docsig( # pylint: disable=too-many-locals,too-many-arguments
check_class,
check_class_constructor,
check_dunders,
check_nested,
check_overridden,
check_protected,
check_property_returns,
Expand Down
1 change: 1 addition & 0 deletions docsig/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def main() -> str | int:
check_protected_class_methods=(
parser.args.check_protected_class_methods
),
check_nested=parser.args.check_nested,
check_overridden=parser.args.check_overridden,
check_protected=parser.args.check_protected,
check_property_returns=parser.args.check_property_returns,
Expand Down
108 changes: 71 additions & 37 deletions docsig/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,89 @@ def __init__( # pylint: disable=too-many-arguments
super().__init__()
self._name = node.name
self._path = f"{path}:" if path is not None else ""
overloads = []
overloads: list[str] = []
returns = None
self._parse_ast(
node,
directives,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
overloads,
returns,
)

def _parse_ast( # pylint: disable=protected-access,too-many-arguments
self,
node,
directives,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
overloads,
returns,
) -> None:
parent_comments, parent_disabled = directives.get(
node.lineno, ([], [])
)
for subnode in node.body:
comments, disabled = directives.get(subnode.lineno, ([], []))
comments.extend(parent_comments)
disabled.extend(parent_disabled)
if isinstance(subnode, _ast.FunctionDef):
func = Function(
subnode,
comments,
directives,
disabled,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
)
if func.isoverloaded:
overloads.append(func.name)
returns = func.signature.rettype
else:
if func.name in overloads:
subnode.returns = returns
# noinspection PyProtectedMember
func._signature._rettype = (
returns
if isinstance(returns, str)
else func._signature._get_rettype(returns)
)
# noinspection PyProtectedMember
func._signature._returns = (
str(func._signature._rettype) != "None"
if hasattr(node, "body"):
for subnode in node.body:
comments, disabled = directives.get(subnode.lineno, ([], []))
comments.extend(parent_comments)
disabled.extend(parent_disabled)
if isinstance(subnode, _ast.FunctionDef):
func = Function(
subnode,
comments,
directives,
disabled,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
)
if func.isoverloaded:
overloads.append(func.name)
returns = func.signature.rettype
else:
if func.name in overloads:
subnode.returns = returns
# noinspection PyProtectedMember
func._signature._rettype = (
returns
if isinstance(returns, str)
else func._signature._get_rettype(returns)
)
# noinspection PyProtectedMember
func._signature._returns = (
str(func._signature._rettype) != "None"
)

self.append(func)
elif isinstance(subnode, _ast.ClassDef):
self.append(
Parent(
subnode,
directives,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
)

self.append(func)
elif isinstance(subnode, _ast.ClassDef):
self.append(
Parent(
)
else:
self._parse_ast(
subnode,
directives,
path,
ignore_args,
ignore_kwargs,
check_class_constructor,
overloads,
returns,
)
)

@property
def path(self) -> str:
Expand Down
Loading
Loading