Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changes/unreleased/Under the Hood-20251120-175805.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Under the Hood
body: Optimize dictionary membership checks by replacing 'in dict.keys()' with 'in dict' for better performance
time: 2025-11-20T17:58:05.215680-08:00
custom:
Author: christopherrya
2 changes: 1 addition & 1 deletion core/dbt/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def diff_of_two_dicts(
dict_diff = {}
dict_b_lowered = {k.casefold(): [x.casefold() for x in v] for k, v in dict_b.items()}
for k in dict_a:
if k.casefold() in dict_b_lowered.keys():
if k.casefold() in dict_b_lowered:
diff = []
for v in dict_a[k]:
if v.casefold() not in dict_b_lowered[k.casefold()]:
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def build_node_edges(nodes: List[ManifestNode]):
for node in nodes:
backward_edges[node.unique_id] = node.depends_on_nodes[:]
for unique_id in backward_edges[node.unique_id]:
if unique_id in forward_edges.keys():
if unique_id in forward_edges:
forward_edges[unique_id].append(node.unique_id)
return _sort_values(forward_edges), _sort_values(backward_edges)

Expand All @@ -591,7 +591,7 @@ def build_macro_edges(nodes: List[Any]):
}
for node in nodes:
for unique_id in node.depends_on_macros:
if unique_id in forward_edges.keys():
if unique_id in forward_edges:
forward_edges[unique_id].append(node.unique_id)
return _sort_values(forward_edges)

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def check_if_can_write_profile(self, profile_name: Optional[str] = None) -> bool
profile_name = profile_name or self.get_profile_name_from_current_project()
with open(profiles_file, "r") as f:
profiles = yaml.safe_load(f) or {}
if profile_name in profiles.keys():
if profile_name in profiles:
response = click.confirm(
f"The profile {profile_name} already exists in "
f"{profiles_file}. Continue and overwrite it?"
Expand Down
Loading