From f82f43d45ac92819e4b46798ae3d04758547b065 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Tue, 27 Feb 2024 17:50:49 -0300 Subject: [PATCH] change from list to gen --- integration_tests/test_django_model_without_dunder_str.py | 6 +++--- src/codemodder/codemods/test/integration_utils.py | 2 +- src/core_codemods/django_model_without_dunder_str.py | 2 +- .../docs/pixee_python_django-model-without-dunder-str.md | 2 +- tests/codemods/test_django_model_without_dunder_str.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration_tests/test_django_model_without_dunder_str.py b/integration_tests/test_django_model_without_dunder_str.py index b059b1a2..0f1b16ae 100644 --- a/integration_tests/test_django_model_without_dunder_str.py +++ b/integration_tests/test_django_model_without_dunder_str.py @@ -2,7 +2,7 @@ DjangoModelWithoutDunderStr, DjangoModelWithoutDunderStrTransformer, ) -from integration_tests.base_test import ( +from codemodder.codemods.test import ( BaseIntegrationTest, original_and_expected_from_code_path, ) @@ -19,7 +19,7 @@ class TestDjangoModelWithoutDunderStr(BaseIntegrationTest): (17, """ model_name = self.__class__.__name__\n"""), ( 18, - """ fields_str = ", ".join([f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields])\n""", + """ fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields))\n""", ), (19, """ return f"{model_name}({fields_str})"\n"""), ], @@ -36,7 +36,7 @@ class TestDjangoModelWithoutDunderStr(BaseIntegrationTest): """+\n""" """+ def __str__(self):\n""" """+ model_name = self.__class__.__name__\n""" - """+ fields_str = ", ".join([f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields])\n""" + """+ fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields))\n""" """+ return f"{model_name}({fields_str})"\n""" ) # fmt: on diff --git a/src/codemodder/codemods/test/integration_utils.py b/src/codemodder/codemods/test/integration_utils.py index 6caa5e73..284a57f9 100644 --- a/src/codemodder/codemods/test/integration_utils.py +++ b/src/codemodder/codemods/test/integration_utils.py @@ -141,7 +141,7 @@ def check_code_before(self): assert code == self.original_code def check_code_after(self) -> ModuleType: - with open(self.code_path, "r", encoding="utf-8") as f: + with open(self.code_path, "r", encoding="utf-8") as f: # type: ignore new_code = f.read() assert new_code == self.expected_new_code return execute_code( diff --git a/src/core_codemods/django_model_without_dunder_str.py b/src/core_codemods/django_model_without_dunder_str.py index 5ce5ebc3..be1da23f 100644 --- a/src/core_codemods/django_model_without_dunder_str.py +++ b/src/core_codemods/django_model_without_dunder_str.py @@ -60,7 +60,7 @@ def dunder_str_method() -> cst.FunctionDef: body=[ cst.parse_statement("model_name = self.__class__.__name__"), cst.parse_statement( - 'fields_str = ", ".join([f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields])' + 'fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields))' ), cst.parse_statement('return f"{model_name}({fields_str})"'), ] diff --git a/src/core_codemods/docs/pixee_python_django-model-without-dunder-str.md b/src/core_codemods/docs/pixee_python_django-model-without-dunder-str.md index 61952c1e..9d3ba768 100644 --- a/src/core_codemods/docs/pixee_python_django-model-without-dunder-str.md +++ b/src/core_codemods/docs/pixee_python_django-model-without-dunder-str.md @@ -12,7 +12,7 @@ class Question(models.Model): + + def __str__(self): + model_name = self.__class__.__name__ -+ fields_str = ", ".join([f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields]) ++ fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields)) + return f"{model_name}({fields_str})" ``` diff --git a/tests/codemods/test_django_model_without_dunder_str.py b/tests/codemods/test_django_model_without_dunder_str.py index 14505491..f230e81c 100644 --- a/tests/codemods/test_django_model_without_dunder_str.py +++ b/tests/codemods/test_django_model_without_dunder_str.py @@ -1,5 +1,5 @@ from core_codemods.django_model_without_dunder_str import DjangoModelWithoutDunderStr -from tests.codemods.base_codemod_test import BaseCodemodTest +from codemodder.codemods.test import BaseCodemodTest class TestDjangoModelWithoutDunderStr(BaseCodemodTest): @@ -49,7 +49,7 @@ def decorated_name(self): def __str__(self): model_name = self.__class__.__name__ - fields_str = ", ".join([f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields]) + fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields)) return f"{model_name}({fields_str})" def something():