Skip to content

Commit

Permalink
Deal with potential recursion error (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Aug 19, 2023
1 parent ecbdfe1 commit 463b196
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- Fixed
- Fixed a bug where raise/return/yield statements in match-case blocks are
incorrectly identified
- Improved
- Used a try/catch block to capture potential recursion error, potentially
due to too complex functions/classes
(https://github.com/jsh9/pydoclint/issues/65)
- Full diff
- https://github.com/jsh9/pydoclint/compare/0.1.9...0.2.0

Expand Down
16 changes: 14 additions & 2 deletions pydoclint/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def collectFuncArgs(node: FuncOrAsyncFuncDef) -> List[ast.arg]:
allArgs.extend(node.args.kwonlyargs)

if node.args.vararg is not None:
vararg = copy.deepcopy(node.args.vararg)
try:
vararg = copy.deepcopy(node.args.vararg)
except RecursionError:
# In rare occasions, using deepcopy could trigger recursion errors
# if the underlying Python code is too complex. And example for
# it is https://github.com/jsh9/pydoclint/issues/65
vararg = copy.copy(node.args.vararg)

# This is a hacky way to ensure that users write '*args' instead
# of 'args' in the docstring, as per the style guide of numpy:
Expand All @@ -29,7 +35,13 @@ def collectFuncArgs(node: FuncOrAsyncFuncDef) -> List[ast.arg]:
allArgs.append(vararg)

if node.args.kwarg is not None:
kwarg = copy.deepcopy(node.args.kwarg)
try:
kwarg = copy.deepcopy(node.args.kwarg)
except RecursionError:
# In rare occasions, using deepcopy could trigger recursion errors
# if the underlying Python code is too complex. And example for
# it is https://github.com/jsh9/pydoclint/issues/65
kwarg = copy.copy(node.args.kwarg)

# This is a hacky way to ensure that users write '**kwargs' instead
# of 'kwargs' in the docstring, as per the style guide of numpy:
Expand Down

0 comments on commit 463b196

Please sign in to comment.