Skip to content

Commit 41e6d99

Browse files
committed
refactor dict.update() to use |= operator
1 parent c185bd4 commit 41e6d99

28 files changed

+394
-476
lines changed

src/pymatgen/analysis/chemenv/coordination_environments/coordination_geometry_finder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ def compute_structure_environments(
613613
optimization: optimization algorithm
614614
615615
Returns:
616-
The StructureEnvironments object containing all the information about the coordination
617-
environments in the structure.
616+
StructureEnvironments: contains all the information about the coordination
617+
environments in the structure.
618618
"""
619619
time_init = time.process_time()
620620
if info is None:

src/pymatgen/analysis/chempot_diagram.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _get_2d_plot(self, elements: list[Element], label_stable: bool | None, eleme
295295
draw_domains[formula] = pts_2d
296296

297297
layout = plotly_layouts["default_layout_2d"].copy()
298-
layout.update(self._get_axis_layout_dict(elements))
298+
layout |= self._get_axis_layout_dict(elements)
299299
if label_stable:
300300
layout["annotations"] = annotations
301301

@@ -366,7 +366,7 @@ def _get_3d_plot(
366366
domain_simplexes[formula] = simplexes
367367

368368
layout = plotly_layouts["default_layout_3d"].copy()
369-
layout["scene"].update(self._get_axis_layout_dict(elements))
369+
layout["scene"] |= self._get_axis_layout_dict(elements)
370370
layout["scene"]["annotations"] = None
371371

372372
if label_stable:
@@ -559,7 +559,7 @@ def _get_annotation(ann_loc: np.ndarray, formula: str) -> dict[str, str | float]
559559
"""Get a Plotly annotation dict given a formula and location."""
560560
formula = htmlify(formula)
561561
annotation = plotly_layouts["default_annotation_layout"].copy()
562-
annotation.update({"x": ann_loc[0], "y": ann_loc[1], "text": formula})
562+
annotation |= {"x": ann_loc[0], "y": ann_loc[1], "text": formula}
563563
if len(ann_loc) == 3:
564564
annotation["z"] = ann_loc[2]
565565
return annotation

src/pymatgen/analysis/ferroelectricity/polarization.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ def zval_dict_from_potcar(potcar) -> dict[str, float]:
7575
7676
potcar: Potcar object
7777
"""
78-
zval_dict = {}
79-
for p in potcar:
80-
zval_dict.update({p.element: p.ZVAL})
81-
return zval_dict
78+
return {p.element: p.ZVAL for p in potcar}
8279

8380

8481
def calc_ionic(site: PeriodicSite, structure: Structure, zval: float) -> np.ndarray:

src/pymatgen/analysis/graphs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ def draw_graph_to_file(
933933
d["label"] = f"{d['weight']:.2f} {units}"
934934

935935
# update edge with our new style attributes
936-
g.edges[u, v, k].update(d)
936+
g.edges[u, v, k] |= d
937937

938938
# optionally remove periodic image edges,
939939
# these can be confusing due to periodic boundaries
@@ -2603,7 +2603,7 @@ def draw_graph_to_file(
26032603
d["label"] = f"{d['weight']:.2f} {units}"
26042604

26052605
# update edge with our new style attributes
2606-
g.edges[u, v, k].update(d)
2606+
g.edges[u, v, k] |= d
26072607

26082608
# optionally remove periodic image edges,
26092609
# these can be confusing due to periodic boundaries

src/pymatgen/analysis/local_env.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ def __init__(
12181218

12191219
# Update any user preference elemental radii
12201220
if el_radius_updates:
1221-
self.el_radius.update(el_radius_updates)
1221+
self.el_radius |= el_radius_updates
12221222

12231223
@property
12241224
def structures_allowed(self) -> bool:
@@ -2755,7 +2755,7 @@ def get_type(self, index):
27552755
raise ValueError("Index for getting order parameter type out-of-bounds!")
27562756
return self._types[index]
27572757

2758-
def get_parameters(self, index):
2758+
def get_parameters(self, index: int) -> list[float]:
27592759
"""Get list of floats that represents
27602760
the parameters associated
27612761
with calculation of the order
@@ -2764,12 +2764,10 @@ def get_parameters(self, index):
27642764
inputted because of processing out of efficiency reasons.
27652765
27662766
Args:
2767-
index (int):
2768-
index of order parameter for which associated parameters
2769-
are to be returned.
2767+
index (int): index of order parameter for which to return associated params.
27702768
27712769
Returns:
2772-
[float]: parameters of a given OP.
2770+
list[float]: parameters of a given OP.
27732771
"""
27742772
if index < 0 or index >= len(self._types):
27752773
raise ValueError("Index for getting parameters associated with order parameter calculation out-of-bounds!")

0 commit comments

Comments
 (0)