Skip to content

Commit

Permalink
Fix metadata key error (#381)
Browse files Browse the repository at this point in the history
* Avoid multiple inheritance in f-str codemod

* Reenable RemoveUnneccessaryFStr
  • Loading branch information
drdavella authored Mar 18, 2024
1 parent 5f2f548 commit 0ae02fe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
5 changes: 0 additions & 5 deletions integration_tests/test_unnecessary_f_str.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from codemodder.codemods.test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
Expand All @@ -10,9 +8,6 @@
)


@pytest.mark.skipif(
True, reason="May fail if it runs after test_sql_parameterization. See Issue #378."
)
class TestFStr(BaseIntegrationTest):
codemod = RemoveUnnecessaryFStr
code_path = "tests/samples/unnecessary_f_str.py"
Expand Down
5 changes: 2 additions & 3 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
from .remove_debug_breakpoint import RemoveDebugBreakpoint
from .remove_future_imports import RemoveFutureImports
from .remove_module_global import RemoveModuleGlobal

# from .remove_unnecessary_f_str import RemoveUnnecessaryFStr
from .remove_unnecessary_f_str import RemoveUnnecessaryFStr
from .remove_unused_imports import RemoveUnusedImports
from .replace_flask_send_file import ReplaceFlaskSendFile
from .requests_verify import RequestsVerify
Expand Down Expand Up @@ -89,7 +88,7 @@
OrderImports,
ProcessSandbox,
RemoveFutureImports,
# RemoveUnnecessaryFStr, # Temporarely disabled due to potential error. See Issue #378.
RemoveUnnecessaryFStr,
RemoveUnusedImports,
RequestsVerify,
SecureFlaskCookie,
Expand Down
18 changes: 6 additions & 12 deletions src/core_codemods/remove_unnecessary_f_str.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import cast

import libcst as cst
import libcst.matchers as m
from libcst.codemod import CodemodContext
from libcst.codemod.commands.unnecessary_format_string import UnnecessaryFormatString

from codemodder.codemods.libcst_transformer import (
Expand All @@ -11,18 +12,9 @@
from core_codemods.api.core_codemod import CoreCodemod


class RemoveUnnecessaryFStrTransform(LibcstResultTransformer, UnnecessaryFormatString):

class RemoveUnnecessaryFStrTransform(LibcstResultTransformer):
change_description = "Remove unnecessary f-string"

def __init__(
self, codemod_context: CodemodContext, *codemod_args, **codemod_kwargs
):
UnnecessaryFormatString.__init__(self, codemod_context)
LibcstResultTransformer.__init__(
self, codemod_context, *codemod_args, **codemod_kwargs
)

@m.leave(m.FormattedString(parts=(m.FormattedStringText(),)))
def _check_formatted_string(
self,
Expand All @@ -34,7 +26,9 @@ def _check_formatted_string(
):
return updated_node

transformed_node = super()._check_formatted_string(_original_node, updated_node)
transformed_node = UnnecessaryFormatString._check_formatted_string(
cast(UnnecessaryFormatString, self), _original_node, updated_node
)
if not _original_node.deep_equals(transformed_node):
self.report_change(_original_node)
return transformed_node
Expand Down
11 changes: 0 additions & 11 deletions tests/codemods/test_remove_unnecessary_f_str.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import pytest

from codemodder.codemods.test import BaseCodemodTest
from core_codemods.remove_unnecessary_f_str import RemoveUnnecessaryFStr


class TestFStr(BaseCodemodTest):
codemod = RemoveUnnecessaryFStr

@pytest.mark.skip(
reason="May fail if it runs after the test_sql_parameterization. See Issue #378."
)
def test_no_change(self, tmpdir):
before = r"""
good: str = "good"
Expand All @@ -23,9 +18,6 @@ def test_no_change(self, tmpdir):
"""
self.run_and_assert(tmpdir, before, before)

@pytest.mark.skip(
reason="May fail if it runs after the test_sql_parameterization. See Issue #378."
)
def test_change(self, tmpdir):
before = r"""
bad: str = f"bad" + "bad"
Expand All @@ -39,9 +31,6 @@ def test_change(self, tmpdir):
"""
self.run_and_assert(tmpdir, before, after, num_changes=3)

@pytest.mark.skip(
reason="May fail if it runs after the test_sql_parameterization. See Issue #378."
)
def test_exclude_line(self, tmpdir):
input_code = (
expected
Expand Down

0 comments on commit 0ae02fe

Please sign in to comment.