Skip to content

Commit b985b94

Browse files
committed
Merge branch 'master' of github.com:materialsproject/pymatgen
2 parents b3d01c4 + bcb2bc2 commit b985b94

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/pymatgen/analysis/phase_diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ class PatchedPhaseDiagram(PhaseDiagram):
16241624

16251625
def __init__(
16261626
self,
1627-
entries: Sequence[PDEntry] | set[PDEntry],
1627+
entries: Sequence[Entry] | set[Entry],
16281628
elements: Sequence[Element] | None = None,
16291629
keep_all_spaces: bool = False,
16301630
verbose: bool = False,

src/pymatgen/entries/compatibility.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import warnings
1111
from collections import defaultdict
12-
from typing import TYPE_CHECKING, TypeAlias, cast
12+
from typing import TYPE_CHECKING, TypeAlias, TypeVar, cast
1313

1414
import numpy as np
1515
from joblib import Parallel, delayed
@@ -77,6 +77,7 @@
7777
raise RuntimeError("MP2020Compatibility.yaml expected to have the same Hubbard U corrections for O and F")
7878

7979
AnyComputedEntry: TypeAlias = ComputedEntry | ComputedStructureEntry
80+
TypeVarAnyEntry = TypeVar("TypeVarAnyEntry", bound=AnyComputedEntry)
8081

8182

8283
class CompatibilityError(Exception):
@@ -577,10 +578,10 @@ def get_adjustments(self, entry: AnyComputedEntry) -> list[EnergyAdjustment]:
577578

578579
def process_entry(
579580
self,
580-
entry: ComputedEntry,
581+
entry: TypeVarAnyEntry,
581582
inplace: bool = True,
582583
**kwargs,
583-
) -> ComputedEntry | None:
584+
) -> TypeVarAnyEntry | None:
584585
"""Process a single entry with the chosen Corrections.
585586
Note that this method may change the original entry.
586587
@@ -595,29 +596,29 @@ def process_entry(
595596
if not inplace:
596597
entry = copy.deepcopy(entry)
597598

598-
_entry: tuple[ComputedEntry, bool] | None = self._process_entry_inplace(entry, **kwargs)
599+
_entry: tuple[TypeVarAnyEntry, bool] | None = self._process_entry_inplace(entry, **kwargs)
599600

600601
return _entry[0] if _entry is not None else None
601602

602603
def _process_entry_inplace(
603604
self,
604-
entry: AnyComputedEntry,
605+
entry: TypeVarAnyEntry,
605606
clean: bool = True,
606607
on_error: Literal["ignore", "warn", "raise"] = "ignore",
607-
) -> tuple[ComputedEntry, bool] | None:
608+
) -> tuple[TypeVarAnyEntry, bool] | None:
608609
"""Process a single entry with the chosen Corrections.
609610
Note that this method will change the original entry.
610611
611612
Args:
612-
entry (AnyComputedEntry): An AnyComputedEntry object.
613+
entry (TypeVarAnyEntry): A TypeVarAnyEntry object.
613614
clean (bool): Whether to remove any previously-applied energy adjustments.
614615
If True, all EnergyAdjustment are removed prior to processing the Entry.
615616
Defaults to True.
616617
on_error ("ignore" | "warn" | "raise"): What to do when get_adjustments(entry)
617618
raises CompatibilityError. Defaults to "ignore".
618619
619620
Returns:
620-
tuple[AnyComputedEntry, ignore_entry (bool)] if entry is compatible, else None.
621+
tuple[TypeVarAnyEntry, ignore_entry (bool)] if entry is compatible, else None.
621622
"""
622623
ignore_entry: bool = False
623624
# If clean, remove all previous adjustments from the entry
@@ -662,13 +663,13 @@ def _process_entry_inplace(
662663

663664
def process_entries(
664665
self,
665-
entries: AnyComputedEntry | list[AnyComputedEntry],
666+
entries: TypeVarAnyEntry | list[TypeVarAnyEntry],
666667
clean: bool = True,
667668
verbose: bool = False,
668669
inplace: bool = True,
669670
n_workers: int = 1,
670671
on_error: Literal["ignore", "warn", "raise"] = "ignore",
671-
) -> list[AnyComputedEntry]:
672+
) -> list[TypeVarAnyEntry]:
672673
"""Process a sequence of entries with the chosen Compatibility scheme.
673674
674675
Warning: This method changes entries in place! All changes can be undone and original entries
@@ -695,7 +696,7 @@ def process_entries(
695696
if isinstance(entries, ComputedEntry): # True for ComputedStructureEntry too
696697
entries = [entries]
697698

698-
processed_entry_list: list[AnyComputedEntry] = []
699+
processed_entry_list: list[TypeVarAnyEntry] = []
699700

700701
# if inplace = False, process entries on a copy
701702
if not inplace:
@@ -1570,13 +1571,13 @@ def get_adjustments(self, entry: ComputedEntry) -> list[EnergyAdjustment]:
15701571

15711572
def process_entries(
15721573
self,
1573-
entries: list[AnyComputedEntry],
1574+
entries: list[TypeVarAnyEntry],
15741575
clean: bool = False,
15751576
verbose: bool = False,
15761577
inplace: bool = True,
15771578
n_workers: int = 1,
15781579
on_error: Literal["ignore", "warn", "raise"] = "ignore",
1579-
) -> list[AnyComputedEntry]:
1580+
) -> list[TypeVarAnyEntry]:
15801581
"""Process a sequence of entries with the chosen Compatibility scheme.
15811582
15821583
Args:

src/pymatgen/entries/mixing_scheme.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from pymatgen.analysis.phase_diagram import PhaseDiagram
1717
from pymatgen.analysis.structure_matcher import StructureMatcher
1818
from pymatgen.entries.compatibility import (
19-
AnyComputedEntry,
2019
Compatibility,
2120
CompatibilityError,
2221
MaterialsProject2020Compatibility,
22+
TypeVarAnyEntry,
2323
)
2424
from pymatgen.entries.computed_entries import ComputedStructureEntry, ConstantEnergyAdjustment
2525
from pymatgen.entries.entry_tools import EntrySet
@@ -121,12 +121,12 @@ def __init__(
121121

122122
def process_entries(
123123
self,
124-
entries: AnyComputedEntry | list[AnyComputedEntry],
124+
entries: TypeVarAnyEntry | list[TypeVarAnyEntry],
125125
clean: bool = True,
126126
verbose: bool = False,
127127
inplace: bool = True,
128128
mixing_state_data=None,
129-
) -> list[AnyComputedEntry]:
129+
) -> list[TypeVarAnyEntry]:
130130
"""Process a sequence of entries with the DFT mixing scheme. Note
131131
that this method will change the data of the original entries.
132132

0 commit comments

Comments
 (0)