Skip to content

Commit 8819383

Browse files
authored
Merge pull request #124 from codeflash-ai/jedi_ctx_fix
found a case where jedi's full name did not start with the module nam…
2 parents 96e2a2e + 64f7927 commit 8819383

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

codeflash/context/code_context_extractor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def get_function_to_optimize_as_function_source(
356356
name.type == "function"
357357
and name.full_name
358358
and name.name == function_to_optimize.function_name
359+
and name.full_name.startswith(name.module_name)
359360
and get_qualified_name(name.module_name, name.full_name) == function_to_optimize.qualified_name
360361
):
361362
function_source = FunctionSource(
@@ -410,6 +411,7 @@ def get_function_sources_from_jedi(
410411
and definition.full_name
411412
and definition.type == "function"
412413
and not belongs_to_function_qualified(definition, qualified_function_name)
414+
and definition.full_name.startswith(definition.module_name)
413415
# Avoid nested functions or classes. Only class.function is allowed
414416
and len((qualified_name := get_qualified_name(definition.module_name, definition.full_name)).split(".")) <= 2
415417
):

codeflash/optimization/function_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def belongs_to_class(name: Name, class_name: str) -> bool:
3131
def belongs_to_function_qualified(name: Name, qualified_function_name: str) -> bool:
3232
"""Check if the given jedi Name is a direct child of the specified function, matched by qualified function name."""
3333
try:
34-
if get_qualified_name(name.module_name, name.full_name) == qualified_function_name:
34+
if name.full_name.startswith(name.module_name) and get_qualified_name(name.module_name, name.full_name) == qualified_function_name:
3535
# Handles function definition and recursive function calls
3636
return False
3737
if name := name.parent():

0 commit comments

Comments
 (0)