Skip to content
Closed
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
17 changes: 11 additions & 6 deletions codeflash/code_utils/static_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pydantic import BaseModel, ConfigDict, field_validator

from codeflash.models.models import FunctionParent

if TYPE_CHECKING:
from codeflash.models.models import FunctionParent

Expand Down Expand Up @@ -139,16 +141,19 @@ def get_first_top_level_function_or_method_ast(


def function_kind(node: ast.FunctionDef | ast.AsyncFunctionDef, parents: list[FunctionParent]) -> FunctionKind | None:
if not parents or parents[0].type in ["FunctionDef", "AsyncFunctionDef"]:
if not parents:
return FunctionKind.FUNCTION
parent_type = parents[0].type
if parent_type in {"FunctionDef", "AsyncFunctionDef"}:
return FunctionKind.FUNCTION
for _i in range(len(parents) - 1, -1, -1):
continue
if parents[0].type == "ClassDef":
if parent_type == "ClassDef":
# Fast path: decorator_list is typically small; scan for 'classmethod' and 'staticmethod'
for decorator in node.decorator_list:
if isinstance(decorator, ast.Name):
if decorator.id == "classmethod":
did = decorator.id
if did == "classmethod":
return FunctionKind.CLASS_METHOD
if decorator.id == "staticmethod":
if did == "staticmethod":
return FunctionKind.STATIC_METHOD
return FunctionKind.INSTANCE_METHOD
return None
Expand Down
Loading