From 03c3782b48430ec027bfd051312dd960eb33d9a9 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Tue, 2 Jan 2024 17:16:23 -0300 Subject: [PATCH] review suggestions --- .pre-commit-config.yaml | 3 +-- src/core_codemods/remove_debug_breakpoint.py | 9 +++++++-- tests/codemods/test_remove_debug_breakpoint.py | 11 +++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 253a2d251..1a1a6736b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,8 +11,7 @@ repos: src/core_codemods/docs/.*| src/codemodder/dependency.py | integration_tests/.*| - tests/codemods/test_remove_debug_breakpoint.py | - tests/test_codemodder.py + tests/.* )$ - id: check-added-large-files - repo: https://github.com/psf/black diff --git a/src/core_codemods/remove_debug_breakpoint.py b/src/core_codemods/remove_debug_breakpoint.py index 21c324fb6..104dcb07a 100644 --- a/src/core_codemods/remove_debug_breakpoint.py +++ b/src/core_codemods/remove_debug_breakpoint.py @@ -6,14 +6,19 @@ class RemoveDebugBreakpoint(BaseCodemod, NameResolutionMixin, AncestorPatternsMixin): NAME = "remove-debug-breakpoint" - SUMMARY = "Remove Breakpoint" + SUMMARY = "Remove Calls to `builtin` `breakpoint` and `pdb.set_trace" REVIEW_GUIDANCE = ReviewGuidance.MERGE_WITHOUT_REVIEW - DESCRIPTION = "Remove calls to builtin `breakpoint` or `pdb.set_trace." + DESCRIPTION = "Remove breakpoint call" REFERENCES: list = [] def leave_Expr( self, original_node: cst.Expr, _ ) -> Union[cst.Expr, cst.RemovalSentinel]: + if not self.filter_by_path_includes_or_excludes( + self.node_position(original_node) + ): + return original_node + match call_node := original_node.value: case cst.Call(): if self.find_base_name( diff --git a/tests/codemods/test_remove_debug_breakpoint.py b/tests/codemods/test_remove_debug_breakpoint.py index 5834cadd7..27e10b834 100644 --- a/tests/codemods/test_remove_debug_breakpoint.py +++ b/tests/codemods/test_remove_debug_breakpoint.py @@ -1,6 +1,5 @@ from core_codemods.remove_debug_breakpoint import RemoveDebugBreakpoint from tests.codemods.base_codemod_test import BaseCodemodTest -from textwrap import dedent class TestRemoveDebugBreakpoint(BaseCodemodTest): @@ -21,7 +20,7 @@ def something(): var = 1 something() """ - self.run_and_assert(tmpdir, dedent(input_code), dedent(expected)) + self.run_and_assert(tmpdir, input_code, expected) assert len(self.file_context.codemod_changes) == 1 def test_builtin_breakpoint_multiple_statements(self, tmpdir): @@ -37,7 +36,7 @@ def something(): print(var); something() """ - self.run_and_assert(tmpdir, dedent(input_code), dedent(expected)) + self.run_and_assert(tmpdir, input_code, expected) assert len(self.file_context.codemod_changes) == 1 def test_inline_pdb(self, tmpdir): @@ -52,7 +51,7 @@ def something(): var = 1 something() """ - self.run_and_assert(tmpdir, dedent(input_code), dedent(expected)) + self.run_and_assert(tmpdir, input_code, expected) assert len(self.file_context.codemod_changes) == 1 def test_pdb_import(self, tmpdir): @@ -68,7 +67,7 @@ def something(): var = 1 something() """ - self.run_and_assert(tmpdir, dedent(input_code), dedent(expected)) + self.run_and_assert(tmpdir, input_code, expected) assert len(self.file_context.codemod_changes) == 1 def test_pdb_from_import(self, tmpdir): @@ -84,5 +83,5 @@ def something(): var = 1 something() """ - self.run_and_assert(tmpdir, dedent(input_code), dedent(expected)) + self.run_and_assert(tmpdir, input_code, expected) assert len(self.file_context.codemod_changes) == 1