70
70
class ElementBase (Enum ):
71
71
"""Element class defined without any enum values so it can be subclassed."""
72
72
73
- def __init__ (self , symbol : SpeciesLike ) -> None :
73
+ def __init__ (self , symbol : str ) -> None :
74
74
"""
75
75
This class provides a basic, immutable representation of an element, including
76
76
all relevant chemical and physical properties. It ensures that elements are
@@ -139,7 +139,7 @@ def __init__(self, symbol: SpeciesLike) -> None:
139
139
- Mendeleev number: D. G. Pettifor, "A chemical scale for crystal-structure maps,"
140
140
Solid State Communications, 1984.
141
141
"""
142
- self .symbol = str ( symbol )
142
+ self .symbol = symbol
143
143
data = _PT_DATA [symbol ]
144
144
145
145
# Store key variables for quick access
@@ -568,8 +568,8 @@ def term_symbols(self) -> list[list[str]]:
568
568
for ML in range (- L , L - 1 , - 1 ):
569
569
for MS in np .arange (S , - S + 1 , 1 ):
570
570
if (ML , MS ) in comb_counter :
571
- comb_counter [ML , MS ] -= 1
572
- if comb_counter [ML , MS ] == 0 :
571
+ comb_counter [ML , MS ] -= 1 # type:ignore[index]
572
+ if comb_counter [ML , MS ] == 0 : # type:ignore[index]
573
573
del comb_counter [ML , MS ]
574
574
return term_symbols
575
575
@@ -849,7 +849,7 @@ def iupac_ordering(self) -> int:
849
849
"""
850
850
return self ._data ["IUPAC ordering" ]
851
851
852
- def as_dict (self ) -> dict [Literal [ "element" , "@module" , "@class" ], str ]:
852
+ def as_dict (self ) -> dict [str , Any ]:
853
853
"""Serialize to MSONable dict representation e.g. to write to disk as JSON."""
854
854
return {
855
855
"@module" : type (self ).__module__ ,
@@ -1041,7 +1041,7 @@ class Species(MSONable, Stringify):
1041
1041
1042
1042
def __init__ (
1043
1043
self ,
1044
- symbol : SpeciesLike ,
1044
+ symbol : str ,
1045
1045
oxidation_state : float | None = None ,
1046
1046
spin : float | None = None ,
1047
1047
) -> None :
@@ -1056,11 +1056,11 @@ def __init__(
1056
1056
ValueError: If oxidation state passed both in symbol string and via
1057
1057
oxidation_state kwarg.
1058
1058
"""
1059
- if oxidation_state is not None and isinstance ( symbol , str ) and symbol .endswith (("+" , "-" )):
1059
+ if oxidation_state is not None and symbol .endswith (("+" , "-" )):
1060
1060
raise ValueError (
1061
1061
f"Oxidation state should be specified either in { symbol = } or as { oxidation_state = } , not both."
1062
1062
)
1063
- if isinstance ( symbol , str ) and symbol .endswith (("+" , "-" )):
1063
+ if symbol .endswith (("+" , "-" )):
1064
1064
# Extract oxidation state from symbol
1065
1065
try :
1066
1066
symbol , oxi = re .match (r"([A-Za-z]+)([0-9\.0-9]*[\+\-])" , symbol ).groups () # type: ignore[union-attr]
@@ -1130,7 +1130,7 @@ def __str__(self) -> str:
1130
1130
if self .oxi_state is not None :
1131
1131
abs_charge = formula_double_format (abs (self .oxi_state ))
1132
1132
if isinstance (abs_charge , float ):
1133
- abs_charge = f"{ abs_charge :.2f} "
1133
+ abs_charge = f"{ abs_charge :.2f} " # type: ignore[assignment]
1134
1134
output += f"{ abs_charge } { '+' if self .oxi_state >= 0 else '-' } "
1135
1135
1136
1136
if self ._spin is not None :
@@ -1319,7 +1319,7 @@ def to_pretty_string(self) -> str:
1319
1319
if self .oxi_state is not None :
1320
1320
abs_charge = formula_double_format (abs (self .oxi_state ))
1321
1321
if isinstance (abs_charge , float ):
1322
- abs_charge = f"{ abs_charge :.2f} "
1322
+ abs_charge = f"{ abs_charge :.2f} " # type: ignore[assignment]
1323
1323
output += f"{ abs_charge } { '+' if self .oxi_state >= 0 else '-' } "
1324
1324
return output
1325
1325
0 commit comments