Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update add usage in function call #425

Merged
merged 1 commit into from
Feb 11, 2025
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
2 changes: 1 addition & 1 deletion src/codegen/sdk/core/detached_symbols/function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


@apidoc
class FunctionCall(Expression[Parent], HasName, Resolvable, Generic[Parent]):

Check failure on line 41 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Type argument "Parent" of "Expression" must be a subtype of "Editable[Any]" [type-var]
"""Abstract representation of a function invocation, e.g. in Python:
```
def f():
Expand All @@ -51,16 +51,16 @@
def __init__(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None:
super().__init__(node, file_node_id, ctx, parent)
# =====[ Grab the function name ]=====
self._name_node = self.child_by_field_name("function", default=Name) or self.child_by_field_name("constructor", default=Name)

Check failure on line 54 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "Expression[FunctionCall[Parent]] | None", variable has type "Name[Any] | ChainedAttribute[Any, Any, Any] | DefinedName[Any] | None") [assignment]
if self._name_node is not None and self._name_node.ts_node.type in ("unary_expression", "await_expression"):
self._name_node = self._parse_expression(self._name_node.ts_node.children[-1], default=Name)

Check failure on line 56 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "Expression[FunctionCall[Parent]]", variable has type "Name[Any] | ChainedAttribute[Any, Any, Any] | DefinedName[Any] | None") [assignment]
# =====[ Grab the arg list ]=====
arg_list_node = node.child_by_field_name("arguments")
if arg_list_node is None:
msg = f"Failed to parse function call. Child 'argument_list' node does not exist. Source: {self.source}"
raise ValueError(msg)
args = [Argument(x, i, self) for i, x in enumerate(arg_list_node.named_children) if x.type != "comment"]

Check failure on line 62 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Need type annotation for "args" [var-annotated]
self._arg_list = Collection(arg_list_node, self.file_node_id, self.ctx, self, children=args)

Check failure on line 63 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 4 to "Collection" has incompatible type "FunctionCall[Parent]"; expected "Self" [arg-type]

def __repr__(self) -> str:
"""Custom string representation showing the function call chain structure.
Expand All @@ -85,7 +85,7 @@
return f"FunctionCall({', '.join(parts)})"

@classmethod
def from_usage(cls, node: Editable[Parent], parent: Parent | None = None) -> Self | None:

Check failure on line 88 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Type argument "Parent" of "Editable" must be a subtype of "Editable[Any]" [type-var]

Check failure on line 88 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Type argument "Parent" of "Editable" must be a subtype of "Editable[Any]" [type-var]
"""Creates a FunctionCall object from an Editable instance that represents a function call.

Takes an Editable node that potentially represents a function call and creates a FunctionCall object from it.
Expand Down Expand Up @@ -114,12 +114,12 @@
Function | None: The parent Function object containing this function call, or None if not found or if the function call is not within a function.
"""
# HACK: This is temporary until we establish a full parent path
if self.file.programming_language == ProgrammingLanguage.TYPESCRIPT:

Check failure on line 117 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: "SourceFile[Any, Any, Any, Any, Any, Any]" has no attribute "programming_language" [attr-defined]
if func := find_first_ancestor(self.ts_node, [function_type.value for function_type in TSFunctionTypeNames]):
from codegen.sdk.typescript.function import TSFunction

return TSFunction.from_function_type(func, self.file_node_id, self.ctx, self.parent)

Check failure on line 121 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 4 to "from_function_type" of "TSFunction" has incompatible type "Parent"; expected "SymbolStatement[Any, Any] | ExportStatement[Any]" [arg-type]
elif self.file.programming_language == ProgrammingLanguage.PYTHON:

Check failure on line 122 in src/codegen/sdk/core/detached_symbols/function_call.py

View workflow job for this annotation

GitHub Actions / mypy

error: "SourceFile[Any, Any, Any, Any, Any, Any]" has no attribute "programming_language" [attr-defined]
if func := find_first_ancestor(self.ts_node, ["function_definition"]):
return self.ctx.node_classes.function_cls(func, self.file_node_id, self.ctx, self.parent)

Expand Down Expand Up @@ -600,7 +600,7 @@
if isinstance(match, FunctionCall):
match._compute_dependencies(usage_type, dest)
for definition in self.function_definition_frames:
definition.add_usage(match=self, dest=dest, usage_type=usage_type, codebase_context=self.ctx)
definition.add_usage(self, usage_type, dest, self.ctx)
else:
match._compute_dependencies(usage_type, dest)

Expand Down