3 ms·
Interesting refactor! This is trivial with codegen.com. Syntax below: # Iterate through all files in the codebase for file in codebase.files: # Chec
by _jayhack_ 2y ago
Interesting refactor!
This is trivial with codegen.com. Syntax below:
# Iterate through all files in the codebase
for file in codebase.files:
# Check for functions with the pytest.fixture decorator
for function in file.functions:
if any(d.name == "fixture" for d in function.decorators):
# Rename the 'db' parameter to 'database'
db_param = function.get_parameter("db")
if db_param:
db_param.set_name("database")
# Log the modification
print(f"Modified {function.name}")
Live example: https://www.codegen.sh/codemod/4697/public/diff https://www.codegen.sh/codemod/4697/public/diff
- poincaredisk 2y agoConsider indenting your code block, it's unreadable as it is now.
- _jayhack_ 2y agoGood call, thank you
- jesus_meza 2y agoThat's pretty sick. Super readable with python :) Is each file getting parsed individually with tree-sitter or how is the codebase object constructed?
- _jayhack_ 2y agoWe do advanced static analysis to provide programmatic access to the type system, etc., based on tree-sitter and in-house tech. This enables APIs such as `function.call_sites`, `symbol.usages`, `class.parent_classes`, and more!
- pksunkara 2y agoWhere can I learn more about this? You guys don't seem to have any docs available.