Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Sep 11, 2024
1 parent b00f7f4 commit ff550d9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pdoc/doc_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def parse(obj):
if isinstance(obj, types.ModuleType):
return _parse_module(src)
elif isinstance(obj, type):
return _parse_class(src, obj)
return _parse_class(src)
else:
return _parse_function(src)

Expand Down Expand Up @@ -233,15 +233,14 @@ def _parse_module(source: str) -> ast.Module:


@cache
def _parse_class(source: str, obj) -> ast.ClassDef:
def _parse_class(source: str) -> ast.ClassDef:
"""
Parse the AST for the source code of a class and return the ast.ClassDef.
Returns an empty ast.ClassDef if source is empty.
"""
tree = _parse(source)
assert len(tree.body) <= 1
if tree.body:
if tree.body and len(tree.body) == 1:
t = tree.body[0]
if isinstance(t, ast.ClassDef):
return t
Expand Down

0 comments on commit ff550d9

Please sign in to comment.