Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace unnecessary dict comprehension by dict() in core #33858

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/api/common/experimental/get_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def get_lineage(
for meta in outlets:
lineage[meta.task_id]["outlets"] = meta.value

return {"task_ids": {k: v for k, v in lineage.items()}}
return {"task_ids": lineage.copy()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {"task_ids": lineage.copy()}
return {"task_ids": dict(lineage)}

Otherwise you've got a copy of defaultdict rather than dict

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t think that’d be problematic though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Taragolis, I should avoid any change in the values in this refactor PR

2 changes: 1 addition & 1 deletion airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def active_runs_of_dags(
else:
query = query.where(cls.state.in_((DagRunState.RUNNING, DagRunState.QUEUED)))
query = query.group_by(cls.dag_id)
return {dag_id: count for dag_id, count in session.execute(query)}
return dict(iter(session.execute(query)))

@classmethod
def next_dagruns_to_examine(
Expand Down
2 changes: 1 addition & 1 deletion airflow/operators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def __deepcopy__(self, memo):
return super().__deepcopy__(memo)

def _execute_python_callable_in_subprocess(self, python_path: Path, tmp_dir: Path):
op_kwargs: dict[str, Any] = {k: v for k, v in self.op_kwargs.items()}
op_kwargs: dict[str, Any] = self.op_kwargs.copy()
if self.templates_dict:
op_kwargs["templates_dict"] = self.templates_dict
input_path = tmp_dir / "script.in"
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def wrapper(*args, **kwargs):
if event and event.startswith("connection."):
extra_fields = _mask_connection_fields(extra_fields)

params = {k: v for k, v in itertools.chain(request.values.items(), request.view_args.items())}
params = {**request.values, **request.view_args}

log = Log(
event=event or f.__name__,
Expand Down
6 changes: 3 additions & 3 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3796,11 +3796,11 @@ def historical_metrics_data(self):
data = {
"dag_run_types": {
**{dag_run_type.value: 0 for dag_run_type in DagRunType},
**{run_type: sum_value for run_type, sum_value in dag_run_types},
**dag_run_types,
},
"dag_run_states": {
**{dag_run_state.value: 0 for dag_run_state in DagRunState},
**{run_state: sum_value for run_state, sum_value in dag_run_states},
**dict(dag_run_states),
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
},
"task_instance_states": {
"no_status": 0,
Expand Down Expand Up @@ -4647,7 +4647,7 @@ def action_mulduplicate(self, connections, session: Session = NEW_SESSION):
select(Connection.conn_id).where(Connection.conn_id.in_(potential_connection_ids))
)

found_conn_id_set = {conn_id for conn_id in query}
found_conn_id_set = set(query)

possible_conn_id_iter = (
connection_id
Expand Down
Loading