Просмотр исходного кода

Merge pull request #1039 from ooooo-create/fix/remove-C408-rule

Clean C408 rule for codestyle
Đỗ Trường Giang 1 год назад
Родитель
Сommit
36188b8544

+ 0 - 1
pyproject.toml

@@ -27,7 +27,6 @@ select = [
     "I001", # isort import order
 ]
 ignore = [      # TODO: to be removed
-    "C408",  # Unnecessary dict call - rewrite as a literal
     "C409",  # Unnecessary list passed to tuple() - rewrite as a tuple literal
 ]
 

+ 1 - 1
taipy/config/section.py

@@ -28,7 +28,7 @@ class Section:
 
     def __init__(self, id, **properties):
         self.id = _validate_id(id)
-        self._properties = properties or dict()
+        self._properties = properties or {}
 
     @abstractmethod
     def __copy__(self):

+ 1 - 1
taipy/core/config/checkers/_config_id_checker.py

@@ -21,7 +21,7 @@ class _ConfigIdChecker(_ConfigChecker):
         super().__init__(config, collector)
 
     def _check(self) -> IssueCollector:
-        existing_config_ids: Dict[str, List[str]] = dict()
+        existing_config_ids: Dict[str, List[str]] = {}
         for entity_type, section_dictionary in self._config._sections.items():
             for config_id in section_dictionary.keys():
                 if config_id in existing_config_ids:

+ 1 - 1
taipy/core/config/core_section.py

@@ -63,7 +63,7 @@ class CoreSection(UniqueSection):
     _REPOSITORY_TYPE_KEY = "repository_type"
     _DEFAULT_REPOSITORY_TYPE = "filesystem"
     _REPOSITORY_PROPERTIES_KEY = "repository_properties"
-    _DEFAULT_REPOSITORY_PROPERTIES: Dict = dict()
+    _DEFAULT_REPOSITORY_PROPERTIES: Dict = {}
 
     _READ_ENTITY_RETRY_KEY = "read_entity_retry"
     _DEFAULT_READ_ENTITY_RETRY = 1

+ 5 - 5
taipy/core/config/scenario_config.py

@@ -136,15 +136,15 @@ class ScenarioConfig(Section):
 
     @classmethod
     def default_config(cls):
-        return ScenarioConfig(cls._DEFAULT_KEY, [], [], None, dict())
+        return ScenarioConfig(cls._DEFAULT_KEY, [], [], None, {})
 
     def _clean(self):
         self._tasks = []
         self._additional_data_nodes = []
         self.frequency = None
-        self.comparators = dict()
-        self.sequences = dict()
-        self._properties = dict()
+        self.comparators = {}
+        self.sequences = {}
+        self._properties = {}
 
     def _to_dict(self) -> Dict[str, Any]:
         return {
@@ -166,7 +166,7 @@ class ScenarioConfig(Section):
         additional_data_nodes = cls.__get_additional_data_node_configs(additional_data_node_ids, config)
 
         frequency = as_dict.pop(cls._FREQUENCY_KEY, None)
-        comparators = as_dict.pop(cls._COMPARATOR_KEY, dict())
+        comparators = as_dict.pop(cls._COMPARATOR_KEY, {})
         sequences = as_dict.pop(cls._SEQUENCES_KEY, {})
 
         for sequence_name, sequence_tasks in sequences.items():

+ 1 - 1
taipy/core/data/_filter.py

@@ -83,7 +83,7 @@ class _FilterDataNode:
         if _FilterDataNode.__is_list_of_dict(data):
             filtered_data = []
             for i, row in key.iterrows():
-                filtered_row = dict()
+                filtered_row = {}
                 for col in row.index:
                     filtered_row[col] = data[i][col] if row[col] else None
                 filtered_data.append(filtered_row)

+ 1 - 1
taipy/core/data/excel.py

@@ -195,7 +195,7 @@ class ExcelDataNode(DataNode, _AbstractFileDataNode, _AbstractTabularDataNode):
         try:
             excel_file = load_workbook(self._path)
             exposed_type = self.properties[self._EXPOSED_TYPE_PROPERTY]
-            work_books = dict()
+            work_books = {}
             sheet_names = excel_file.sheetnames
 
             user_provided_sheet_names = self.properties.get(self.__SHEET_NAME_PROPERTY) or []

+ 1 - 1
taipy/core/taipy.py

@@ -1007,7 +1007,7 @@ def get_parents(
     if isinstance(entity, str):
         entity = get(entity)
 
-    parent_dict = parent_dict or dict()
+    parent_dict = parent_dict or {}
 
     if isinstance(entity, (Scenario, Cycle)):
         return parent_dict

+ 2 - 2
taipy/gui_core/_adapters.py

@@ -117,12 +117,12 @@ class _GuiCoreScenarioDagAdapter(_TaipyBase):
             try:
                 if scenario := core_get(data.id):
                     dag = scenario._get_dag()
-                    nodes = dict()
+                    nodes = {}
                     for id, node in dag.nodes.items():
                         entityType = _GuiCoreScenarioDagAdapter.get_entity_type(node)
                         cat = nodes.get(entityType)
                         if cat is None:
-                            cat = dict()
+                            cat = {}
                             nodes[entityType] = cat
                         cat[id] = {
                             "name": node.entity.get_simple_label(),

+ 2 - 4
taipy/gui_core/_context.py

@@ -93,7 +93,7 @@ class _GuiCoreContext(CoreEventConsumerBase):
         self.data_nodes_by_owner: t.Optional[t.Dict[t.Optional[str], DataNode]] = None
         self.scenario_configs: t.Optional[t.List[t.Tuple[str, str]]] = None
         self.jobs_list: t.Optional[t.List[Job]] = None
-        self.client_submission: t.Dict[str, SubmissionStatus] = dict()
+        self.client_submission: t.Dict[str, SubmissionStatus] = {}
         # register to taipy core notification
         reg_id, reg_queue = Notifier.register()
         # locks
@@ -345,9 +345,7 @@ class _GuiCoreContext(CoreEventConsumerBase):
                                     "config": scenario_config,
                                     "date": date,
                                     "label": name,
-                                    "properties": {
-                                        v.get("key"): v.get("value") for v in data.get("properties", dict())
-                                    },
+                                    "properties": {v.get("key"): v.get("value") for v in data.get("properties", {})},
                                 },
                             ],
                         )

+ 1 - 1
tests/core/conftest.py

@@ -222,7 +222,7 @@ def data_node_model():
         "owner_id",
         list({"parent_id_1", "parent_id_2"}),
         datetime(1985, 10, 14, 2, 30, 0).isoformat(),
-        [dict(timestamp=datetime(1985, 10, 14, 2, 30, 0).isoformat(), job_id="job_id")],
+        [{"timestamp": datetime(1985, 10, 14, 2, 30, 0).isoformat(), "job_id": "job_id"}],
         "latest",
         None,
         None,

+ 2 - 2
tests/core/cycle/test_cycle.py

@@ -220,7 +220,7 @@ def test_auto_set_and_reload(current_datetime):
     cycle_1.properties.update({"temp_key_3": 1})
     assert cycle_1.properties == {"key": "value", "qux": 5, "temp_key_3": 1}
     assert cycle_2.properties == {"key": "value", "qux": 5, "temp_key_3": 1}
-    cycle_1.properties.update(dict())
+    cycle_1.properties.update({})
     assert cycle_1.properties == {"key": "value", "qux": 5, "temp_key_3": 1}
     assert cycle_2.properties == {"key": "value", "qux": 5, "temp_key_3": 1}
     cycle_1.properties.pop("key")
@@ -253,7 +253,7 @@ def test_auto_set_and_reload(current_datetime):
         cycle.properties.update({"temp_key_4": 1})
         cycle.properties.update({"temp_key_5": 2})
         cycle.properties.pop("temp_key_5")
-        cycle.properties.update(dict())
+        cycle.properties.update({})
 
         assert cycle.frequency == Frequency.MONTHLY
         assert cycle.creation_date == new_datetime_2

+ 6 - 6
tests/core/data/test_data_node.py

@@ -68,7 +68,7 @@ class TestDataNode:
             "a_scenario_id",
             {"a_parent_id"},
             a_date,
-            [dict(job_id="a_job_id")],
+            [{"job_id": "a_job_id"}],
             edit_in_progress=False,
             prop="erty",
             name="a name",
@@ -408,7 +408,7 @@ class TestDataNode:
             owner_id=None,
             parent_ids=None,
             last_edit_date=current_datetime,
-            edits=[dict(job_id="a_job_id")],
+            edits=[{"job_id": "a_job_id"}],
             edit_in_progress=False,
             validity_period=None,
             properties={
@@ -582,7 +582,7 @@ class TestDataNode:
         dn_1.properties.update({"temp_key_3": 1})
         assert dn_1.properties == {"qux": 5, "temp_key_3": 1, "name": "def"}
         assert dn_2.properties == {"qux": 5, "temp_key_3": 1, "name": "def"}
-        dn_1.properties.update(dict())
+        dn_1.properties.update({})
         assert dn_1.properties == {"qux": 5, "temp_key_3": 1, "name": "def"}
         assert dn_2.properties == {"qux": 5, "temp_key_3": 1, "name": "def"}
         dn_1.properties["temp_key_4"] = 0
@@ -601,7 +601,7 @@ class TestDataNode:
             dn.properties.update({"temp_key_4": 1})
             dn.properties.update({"temp_key_5": 2})
             dn.properties.pop("temp_key_5")
-            dn.properties.update(dict())
+            dn.properties.update({})
 
             assert dn.properties["qux"] == 5
             assert dn.properties["temp_key_3"] == 1
@@ -681,7 +681,7 @@ class TestDataNode:
             "a_scenario_id",
             {"a_parent_id"},
             a_date,
-            [dict(job_id="a_job_id")],
+            [{"job_id": "a_job_id"}],
             edit_in_progress=False,
             prop="erty",
             name="a name",
@@ -707,7 +707,7 @@ class TestDataNode:
             "a_scenario_id",
             {"a_parent_id"},
             a_date,
-            [dict(job_id="a_job_id")],
+            [{"job_id": "a_job_id"}],
             edit_in_progress=False,
             label="a label",
             name="a name",

+ 4 - 5
tests/core/scenario/test_scenario.py

@@ -377,7 +377,7 @@ def test_add_rename_and_remove_sequences():
     data_node_3 = InMemoryDataNode("qux", Scope.SCENARIO, "s3")
     data_node_4 = InMemoryDataNode("quux", Scope.SCENARIO, "s4")
     data_node_5 = InMemoryDataNode("quuz", Scope.SCENARIO, "s5")
-    task_1 = Task("grault",{}, print,[data_node_1, data_node_2],[data_node_3], TaskId("t1"))
+    task_1 = Task("grault", {}, print, [data_node_1, data_node_2], [data_node_3], TaskId("t1"))
     task_2 = Task("garply", {}, print, [data_node_3], id=TaskId("t2"))
     task_3 = Task("waldo", {}, print, [data_node_3], None, id=TaskId("t3"))
     task_4 = Task("fred", {}, print, [data_node_3], [data_node_4], TaskId("t4"))
@@ -431,7 +431,7 @@ def test_add_rename_and_remove_sequences():
 
 
 def test_update_sequence(data_node):
-    task_1 = Task("foo",{}, print,[data_node],[], TaskId("t1"))
+    task_1 = Task("foo", {}, print, [data_node], [], TaskId("t1"))
     task_2 = Task("bar", {}, print, [], [data_node], id=TaskId("t2"))
     scenario = Scenario("baz", {task_1, task_2}, {})
     scenario.add_sequence("seq_1", [task_1])
@@ -472,7 +472,6 @@ def test_add_rename_and_remove_sequences_within_context(data_node):
     assert len(scenario.sequences) == 0
 
 
-
 def test_add_property_to_scenario():
     scenario = Scenario("foo", set(), {"key": "value"})
     assert scenario.properties == {"key": "value"}
@@ -798,7 +797,7 @@ def test_auto_set_and_reload_properties():
     scenario_1.properties.update({"temp_key_3": 1})
     assert scenario_1.properties == {"name": "baz", "qux": 5, "temp_key_3": 1}
     assert scenario_2.properties == {"name": "baz", "qux": 5, "temp_key_3": 1}
-    scenario_1.properties.update(dict())
+    scenario_1.properties.update({})
     assert scenario_1.properties == {"name": "baz", "qux": 5, "temp_key_3": 1}
     assert scenario_2.properties == {"name": "baz", "qux": 5, "temp_key_3": 1}
     scenario_1.properties["temp_key_4"] = 0
@@ -816,7 +815,7 @@ def test_auto_set_and_reload_properties():
         scenario.properties.update({"temp_key_4": 1})
         scenario.properties.update({"temp_key_5": 2})
         scenario.properties.pop("temp_key_5")
-        scenario.properties.update(dict())
+        scenario.properties.update({})
 
         assert scenario._is_in_context
         assert scenario.properties["qux"] == 5

+ 2 - 2
tests/core/sequence/test_sequence.py

@@ -657,7 +657,7 @@ def test_auto_set_and_reload_properties():
     sequence_1.properties.update({"temp_key_3": 1})
     assert sequence_1.properties == {"name": "foo", "qux": 5, "temp_key_3": 1}
     assert sequence_2.properties == {"name": "foo", "qux": 5, "temp_key_3": 1}
-    sequence_1.properties.update(dict())
+    sequence_1.properties.update({})
     assert sequence_1.properties == {"name": "foo", "qux": 5, "temp_key_3": 1}
     assert sequence_2.properties == {"name": "foo", "qux": 5, "temp_key_3": 1}
     sequence_1.properties["temp_key_4"] = 0
@@ -676,7 +676,7 @@ def test_auto_set_and_reload_properties():
         sequence.properties.update({"temp_key_4": 1})
         sequence.properties.update({"temp_key_5": 2})
         sequence.properties.pop("temp_key_5")
-        sequence.properties.update(dict())
+        sequence.properties.update({})
 
         assert sequence._is_in_context
         assert sequence.properties["qux"] == 5

+ 2 - 2
tests/core/submission/test_submission.py

@@ -396,7 +396,7 @@ def test_auto_set_and_reload_properties():
     submission_1.properties.update({"temp_key_3": 1})
     assert submission_1.properties == {"qux": 5, "temp_key_3": 1}
     assert submission_2.properties == {"qux": 5, "temp_key_3": 1}
-    submission_1.properties.update(dict())
+    submission_1.properties.update({})
     assert submission_1.properties == {"qux": 5, "temp_key_3": 1}
     assert submission_2.properties == {"qux": 5, "temp_key_3": 1}
     submission_1.properties["temp_key_4"] = 0
@@ -414,7 +414,7 @@ def test_auto_set_and_reload_properties():
         submission.properties.update({"temp_key_4": 1})
         submission.properties.update({"temp_key_5": 2})
         submission.properties.pop("temp_key_5")
-        submission.properties.update(dict())
+        submission.properties.update({})
 
         assert submission.properties["qux"] == 5
         assert submission.properties["temp_key_3"] == 1

+ 2 - 2
tests/core/task/test_task.py

@@ -276,7 +276,7 @@ def test_auto_set_and_reload_properties():
     task_1.properties.update({"temp_key_3": 1})
     assert task_1.properties == {"qux": 5, "temp_key_3": 1}
     assert task_2.properties == {"qux": 5, "temp_key_3": 1}
-    task_1.properties.update(dict())
+    task_1.properties.update({})
     assert task_1.properties == {"qux": 5, "temp_key_3": 1}
     assert task_2.properties == {"qux": 5, "temp_key_3": 1}
     task_1.properties["temp_key_4"] = 0
@@ -295,7 +295,7 @@ def test_auto_set_and_reload_properties():
         task.properties.update({"temp_key_4": 1})
         task.properties.update({"temp_key_5": 2})
         task.properties.pop("temp_key_5")
-        task.properties.update(dict())
+        task.properties.update({})
 
         assert task._is_in_context
         assert task.properties["qux"] == 5

+ 1 - 1
tests/gui/server/http/test_extension.py

@@ -21,7 +21,7 @@ class MyLibrary(ElementLibrary):
         return "taipy_extension_example"
 
     def get_elements(self):
-        return dict()
+        return {}
 
 
 def test_extension_no_config(gui: Gui, helpers):

+ 1 - 1
tests/templates/utils.py

@@ -21,7 +21,7 @@ def _bytes_to_str(b: bytes):
 
 def _run_template(taipy_path, cwd, main_path, time_out=30):
     """Run the templates on a subprocess and get stdout after timeout"""
-    env = dict(PYTHONPATH=taipy_path)
+    env = {"PYTHONPATH": taipy_path}
     if platform.system() == "Windows":
         env.update(os.environ)
     with subprocess.Popen(