Skip to content

Commit

Permalink
change from list to gen
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Feb 28, 2024
1 parent 696a581 commit c5b5536
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions integration_tests/test_django_model_without_dunder_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DjangoModelWithoutDunderStr,
DjangoModelWithoutDunderStrTransformer,
)
from integration_tests.base_test import (
from codemodder.codemods.test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)
Expand All @@ -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"""),
],
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/codemodder/codemods/test/integration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/django_model_without_dunder_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
```

Expand Down
4 changes: 2 additions & 2 deletions tests/codemods/test_django_model_without_dunder_str.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit c5b5536

Please sign in to comment.