Repository: Kostiantyn-Salnykov/fastapi-mongodb (language: python)

Issue:
Replace Generator with Collection and Convert For loop to List
- An identity generator can be replaced directly with the collection in this Function `BaseRepository.convert_many_results`.
- Replaces `if` expressions that compare to the target with `or` in this Function `BaseProfiler.__init__`.
- Converts a `for` loop into a list comprehension in this Function `BaseProfiler._get_trace_malloc_filters`.


Discussion / hints:

Fix patch:
diff --git a/fastapi_mongodb/helpers.py b/fastapi_mongodb/helpers.py
index c34a1f8..fa07e67 100644
--- a/fastapi_mongodb/helpers.py
+++ b/fastapi_mongodb/helpers.py
@@ -127,8 +127,8 @@ def __init__(
     ):
         self.number_frames = number_frames
         self.clear_traces = clear_traces
-        self.include_files = include_files if include_files else []
-        self.exclude_files = exclude_files if exclude_files else []
+        self.include_files = include_files or []
+        self.exclude_files = exclude_files or []
         self.show_memory = show_memory
         self._start_time = None
         self._end_time = None
@@ -179,9 +179,11 @@ def _end_trace_malloc(self):
     def _get_trace_malloc_filters(
         self,
     ) -> list[typing.Union[tracemalloc.Filter, tracemalloc.DomainFilter]]:
-        filters = []
-        for file_name in self.include_files:
-            filters.append(tracemalloc.Filter(inclusive=True, filename_pattern=file_name))
+        filters = [
+            tracemalloc.Filter(inclusive=True, filename_pattern=file_name)
+            for file_name in self.include_files
+        ]
+
         for file_name in self.exclude_files:
             filters.append(tracemalloc.Filter(inclusive=False, filename_pattern=file_name))
         return filters


Test patch:
diff --git a/fastapi_mongodb/tests/test_db.py b/fastapi_mongodb/tests/test_db.py
index 48277fa..8a18591 100644
--- a/fastapi_mongodb/tests/test_db.py
+++ b/fastapi_mongodb/tests/test_db.py
@@ -196,11 +196,7 @@ def test_opened(self):
         self.debug_mock.assert_called_once_with(f"Topology with id {self.event.topology_id} opened")
 
     def test_description_changed(self):
-        self.event.new_description.has_writable_server.return_value = False
-        self.event.new_description.has_readable_server.return_value = False
-
-        self.logger.description_changed(event=self.event)
-
+        self._extracted_from_test_description_changed_not_changed_2(False)
         self.debug_mock.assert_has_calls(
             calls=[
                 mock_call(f"Topology description updated for topology id {self.event.topology_id}"),
@@ -218,15 +214,16 @@ def test_description_changed_not_changed(self):
         expected_mock = MagicMock()
         self.event.previous_description.topology_type = expected_mock
         self.event.new_description.topology_type = expected_mock
-        self.event.new_description.has_writable_server.return_value = True
-        self.event.new_description.has_readable_server.return_value = True
-
-        self.logger.description_changed(event=self.event)
-
+        self._extracted_from_test_description_changed_not_changed_2(True)
         self.debug_mock.assert_called_once_with(
             f"Topology description updated for topology id {self.event.topology_id}"
         )
 
+    def _extracted_from_test_description_changed_not_changed_2(self, arg0):
+        self.event.new_description.has_writable_server.return_value = arg0
+        self.event.new_description.has_readable_server.return_value = arg0
+        self.logger.description_changed(event=self.event)
+
     def test_closed(self):
         self.logger.closed(event=self.event)
 
diff --git a/fastapi_mongodb/tests/test_pagination.py b/fastapi_mongodb/tests/test_pagination.py
index f6c3a3a..7fb32b3 100644
--- a/fastapi_mongodb/tests/test_pagination.py
+++ b/fastapi_mongodb/tests/test_pagination.py
@@ -13,9 +13,9 @@ def test__call__default(self):
 
         result = self.pagination_instance(limit=default_limit, offset=default_offset)
 
-        self.assertIsInstance(result, Paginator)
-        self.assertEqual(default_limit, result.limit)
-        self.assertEqual(default_offset, result.skip)
+        self._extracted_from_test__call__custom_7(
+            result, default_limit, default_offset
+        )
 
     def test__call__custom(self):
         custom_limit = self.faker.pyint(
@@ -26,6 +26,9 @@ def test__call__custom(self):
 
         result = self.pagination_instance(offset=custom_offset, limit=custom_limit)
 
+        self._extracted_from_test__call__custom_7(result, custom_limit, custom_offset)
+
+    def _extracted_from_test__call__custom_7(self, result, arg1, arg2):
         self.assertIsInstance(result, Paginator)
-        self.assertEqual(custom_limit, result.limit)
-        self.assertEqual(custom_offset, result.skip)
+        self.assertEqual(arg1, result.limit)
+        self.assertEqual(arg2, result.skip)