Skip to content
Merged
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
39 changes: 1 addition & 38 deletions src/python_introspect/signature_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,7 @@ def extract(target: Union[Callable, type]) -> DocstringInfo:
if not docstring:
return DocstringInfo(parameters={})

# Try AST-based parsing first for better accuracy
try:
return DocstringExtractor._parse_docstring_ast(actual_target, docstring)
except Exception:
# Fall back to regex-based parsing
return DocstringExtractor._parse_docstring(docstring)
return DocstringExtractor._parse_docstring(docstring)

@staticmethod
def _resolve_lazy_target(target: Union[Callable, type]) -> Union[Callable, type]:
Expand All @@ -448,38 +443,6 @@ def _resolve_lazy_target(target: Union[Callable, type]) -> Union[Callable, type]
return target
return _resolve_type(target)

@staticmethod
def _parse_docstring_ast(target: Union[Callable, type], docstring: str) -> DocstringInfo:
"""Parse docstring using AST for more accurate extraction.

This method uses AST to parse the source code and extract docstring
information more accurately, especially for complex multiline descriptions.
"""
try:
# Get source code
source = inspect.getsource(target)
tree = ast.parse(source)

# Find the function/class node
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
if ast.get_docstring(node) == docstring:
return DocstringExtractor._parse_ast_docstring(node, docstring)

# Fallback to regex parsing if AST parsing fails
return DocstringExtractor._parse_docstring(docstring)

except Exception:
# Fallback to regex parsing
return DocstringExtractor._parse_docstring(docstring)

@staticmethod
def _parse_ast_docstring(node: Union[ast.FunctionDef, ast.ClassDef], docstring: str) -> DocstringInfo:
"""Parse docstring from AST node with enhanced multiline support."""
# For now, use the improved regex parser
# This can be extended later with more sophisticated AST-based parsing
return DocstringExtractor._parse_docstring(docstring)

@staticmethod
def _parse_docstring(docstring: str) -> DocstringInfo:
"""Parse a docstring into structured components with improved multiline support.
Expand Down
Loading