Skip to content

Commit 184da57

Browse files
fhightowerclaude
andcommitted
Widen _python_ast_exception_name return type to Optional[str]
It can fall through all branches and implicitly return None; annotate it accordingly (and return None explicitly) instead of suppressing mypy with type: ignore[return]. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 366ef86 commit 184da57

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

d8s_python/ast_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# TODO: all of these functions where code_text is given should also be able to read a file at a given path (?)
88

99

10-
def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> str: # type: ignore[return]
10+
def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> Optional[str]:
1111
"""."""
1212
if hasattr(node, "exc") and node.exc: # this handles ast.Raise nodes
1313
if hasattr(
@@ -40,6 +40,8 @@ def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> str
4040
elif hasattr(node, "id"): # this handles situations where the exception being raised is an ast.Name (e.g. "e")
4141
return node.id
4242

43+
return None
44+
4345

4446
def python_ast_raise_name(node: ast.Raise) -> Optional[str]:
4547
"""Get the name of the exception raise by the given ast.Raise object."""

0 commit comments

Comments
 (0)