99import os
1010import warnings
1111from collections import defaultdict
12- from typing import TYPE_CHECKING , TypeAlias , cast
12+ from typing import TYPE_CHECKING , TypeAlias , TypeVar , cast
1313
1414import numpy as np
1515from joblib import Parallel , delayed
7777 raise RuntimeError ("MP2020Compatibility.yaml expected to have the same Hubbard U corrections for O and F" )
7878
7979AnyComputedEntry : TypeAlias = ComputedEntry | ComputedStructureEntry
80+ TypeVarAnyEntry = TypeVar ("TypeVarAnyEntry" , bound = AnyComputedEntry )
8081
8182
8283class 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:
0 commit comments