Skip to content

Commit

Permalink
add utils.is_implemented raises node handling
Browse files Browse the repository at this point in the history
  • Loading branch information
camriddell committed Feb 1, 2025
1 parent 956a12c commit fd40698
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ def has_operation(native_namespace: ModuleType, operation: Any) -> bool:


def is_implemented(func: Callable[..., Any]) -> bool:
from ast import Call
from ast import Name
from ast import NodeVisitor
from ast import Raise
from ast import Return
Expand All @@ -1288,7 +1290,12 @@ def visit_Return(self, node: Return) -> None: # noqa: N802
self.has_return = True

def visit_Raise(self, node: Raise) -> None: # noqa: N802
if node.exc.func.id == "NotImplementedError": # type: ignore[union-attr]
if isinstance(node.exc, Call):
name_node = node.exc.func
elif isinstance(node.exc, Name):
name_node = node.exc

if name_node.id == "NotImplementedError": # type: ignore[attr-defined]
self.has_notimplemented = True

source = dedent(getsource(func))
Expand Down

0 comments on commit fd40698

Please sign in to comment.