@@ -1088,15 +1088,17 @@ def __repr__(self) -> str:
1088
1088
return f"Species { self } "
1089
1089
1090
1090
def __str__ (self ) -> str :
1091
- output = self .name if hasattr (self , "name" ) else self .symbol
1092
- if self .oxi_state is not None :
1093
- abs_charge = formula_double_format (abs (self .oxi_state ))
1091
+ name = getattr (self , "name" , None )
1092
+ output = name or self .symbol
1093
+ oxi_state = self .oxi_state
1094
+ if oxi_state is not None :
1095
+ abs_charge = formula_double_format (abs (oxi_state ))
1094
1096
if isinstance (abs_charge , float ):
1095
1097
abs_charge = f"{ abs_charge :.2f} " # type: ignore[assignment]
1096
- output += f"{ abs_charge } { '+' if self . oxi_state >= 0 else '-' } "
1098
+ output += f"{ abs_charge } { '+' if oxi_state >= 0 else '-' } "
1097
1099
1098
- if self ._spin is not None :
1099
- spin = self . _spin
1100
+ spin = self ._spin
1101
+ if spin is not None :
1100
1102
output += f",{ spin = } "
1101
1103
return output
1102
1104
@@ -1484,10 +1486,11 @@ def __repr__(self) -> str:
1484
1486
1485
1487
def __str__ (self ) -> str :
1486
1488
output = self .symbol
1487
- if self .oxi_state is not None :
1488
- output += f"{ formula_double_format (abs (self .oxi_state ))} { '+' if self .oxi_state >= 0 else '-' } "
1489
- if self ._spin is not None :
1490
- spin = self ._spin
1489
+ oxi_state = self .oxi_state
1490
+ if oxi_state is not None :
1491
+ output += f"{ formula_double_format (abs (oxi_state ))} { '+' if oxi_state >= 0 else '-' } "
1492
+ spin = self ._spin
1493
+ if spin is not None :
1491
1494
output += f",{ spin = } "
1492
1495
return output
1493
1496
0 commit comments