Skip to content

Commit

Permalink
Added check to ignore __init__.py files
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Oct 26, 2023
1 parent aa6d0f5 commit ace5ea6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/core_codemods/remove_unused_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(self, codemod_context: CodemodContext, *codemod_args):
BaseCodemod.__init__(self, *codemod_args)

def transform_module_impl(self, tree: cst.Module) -> cst.Module:
# Do nothing in __init__.py files
if self.file_context.file_path.name == "__init__.py":
return tree
gather_unused_visitor = GatherUnusedImportsVisitor(self.context)
tree.visit(gather_unused_visitor)
# filter the gathered imports by line excludes/includes
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/base_codemod_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_method(self):
self.file_context = None

def run_and_assert(self, tmpdir, input_code, expected):
tmp_file_path = tmpdir / "code.py"
tmp_file_path = Path(tmpdir / "code.py")
self.run_and_assert_filepath(tmpdir, tmp_file_path, input_code, expected)

def run_and_assert_filepath(self, root, file_path, input_code, expected):
Expand Down

0 comments on commit ace5ea6

Please sign in to comment.