Skip to content

Commit

Permalink
Merge pull request Avaiga#1039 from ooooo-create/fix/remove-C408-rule
Browse files Browse the repository at this point in the history
Clean C408 rule for codestyle
  • Loading branch information
trgiangdo authored Mar 25, 2024
2 parents 8160791 + 7cc265c commit 36188b8
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 40 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down
2 changes: 1 addition & 1 deletion taipy/config/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/config/checkers/_config_id_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, config: _Config, collector: IssueCollector):
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:
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/config/core_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions taipy/core/config/scenario_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ def __get_all_unique_data_nodes(self) -> List[DataNodeConfig]:

@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 {
Expand All @@ -166,7 +166,7 @@ def _from_dict(cls, as_dict: Dict[str, Any], id: str, config: Optional[_Config]
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():
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/data/_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __getitem_dataframe(data, key: pd.DataFrame):
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)
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/data/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _read_as(self):
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 []
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/taipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ def update_parent_dict(parents_set, parent_dict):
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
Expand Down
4 changes: 2 additions & 2 deletions taipy/gui_core/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def get(self):
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(),
Expand Down
6 changes: 2 additions & 4 deletions taipy/gui_core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, gui: Gui) -> None:
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
Expand Down Expand Up @@ -345,9 +345,7 @@ def crud_scenario(self, state: State, id: str, payload: t.Dict[str, str]): # no
"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", {})},
},
],
)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/core/cycle/test_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/core/data/test_data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_create(self):
"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",
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_auto_set_and_reload(self, current_datetime):
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={
Expand Down Expand Up @@ -582,7 +582,7 @@ def test_auto_set_and_reload_properties(self):
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
Expand All @@ -601,7 +601,7 @@ def test_auto_set_and_reload_properties(self):
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
Expand Down Expand Up @@ -681,7 +681,7 @@ def test_label(self):
"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",
Expand All @@ -707,7 +707,7 @@ def test_explicit_label(self):
"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",
Expand Down
9 changes: 4 additions & 5 deletions tests/core/scenario/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/core/sequence/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/core/submission/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/core/task/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/gui/server/http/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_name(self) -> str:
return "taipy_extension_example"

def get_elements(self):
return dict()
return {}


def test_extension_no_config(gui: Gui, helpers):
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 36188b8

Please sign in to comment.