Skip to content

Cleaned up canonical codemods #26

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

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def f() -> FastStr:
def execute(self, codebase: Codebase) -> None:
# Iterate over all functions in the codebase
for function in codebase.functions:
# Check if the function's return type annotation is 'BillPayVendor'
# Check if the function's return type annotation is 'str'
if (return_type := function.return_type) and return_type.source == "str":
# Update the return type to 'Payee'
# Update the return type to 'FastStr'
function.set_return_type("FastStr")

# Add import for 'FastStr' if it doesn't exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def execute(self, codebase: Codebase) -> None:
for file in codebase.files:
for function in file.functions:
# Check if any local variable names contain "position"
business_vendor_usages = function.code_block.get_variable_usages("position", fuzzy_match=True)
if len(business_vendor_usages) > 0:
position_usages = function.code_block.get_variable_usages("position", fuzzy_match=True)
if len(position_usages) > 0:
# Rename
function.rename_local_variable("position", "pos", fuzzy_match=True)
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def execute(self, codebase: Codebase) -> None:
# Add import of `CacheConfig` to function definition file
function.file.add_symbol_import(class_b_symb)

# Check if the function body is using `bill_pay_vendor`
# Check if the function body is using `cache_config`
if len(function.code_block.get_variable_usages(class_a_param.name)) > 0:
# Add "wrapper" inside the function
# This creates the `business_vendor` variable internally
# This creates the `cache_config` variable internally
proxy_var_declaration = f"""{class_a_param.name} = cache_config.settings # added by Codegen"""
function.prepend_statements(proxy_var_declaration)

# Update all callsites of original function to take in `payee` instead of `bill_pay_vendor`
# Update all callsites of original function to take in `cache_config` instead of `graph_rag_config`
fcalls = function.call_sites
for fcall in fcalls:
arg = fcall.get_arg_by_parameter_name(class_a_param.name)
Expand Down
Loading