From 2f8d6aeec277c5a7c3224ac186191513f57ae0ce Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel) YANG" Date: Fri, 10 Jan 2025 02:14:21 +0800 Subject: [PATCH] Change `get` default from empty list (`[]`) to `False` when used as `bool` or condition check for `Outcar` parsing methods (#4196) * change boolean default * tiny enhancement of type --- src/pymatgen/io/vasp/outputs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pymatgen/io/vasp/outputs.py b/src/pymatgen/io/vasp/outputs.py index 1a15bfb8f2c..633bf4b3379 100644 --- a/src/pymatgen/io/vasp/outputs.py +++ b/src/pymatgen/io/vasp/outputs.py @@ -2150,7 +2150,7 @@ def __init__(self, filename: PathLike) -> None: self.final_energy = e0 self.final_energy_wo_entrp = e_wo_entrp self.final_fr_energy = e_fr_energy - self.data: dict = {} + self.data: dict[str, Any] = {} # Read "number of bands" (NBANDS) self.read_pattern( @@ -2200,11 +2200,11 @@ def __init__(self, filename: PathLike) -> None: # Check if calculation is spin polarized self.read_pattern({"spin": r"ISPIN\s*=\s*2"}) - self.spin = bool(self.data.get("spin", [])) + self.spin = bool(self.data.get("spin", False)) # Check if calculation is non-collinear self.read_pattern({"noncollinear": r"LNONCOLLINEAR\s*=\s*T"}) - self.noncollinear = bool(self.data.get("noncollinear", [])) + self.noncollinear = bool(self.data.get("noncollinear", False)) # Check if the calculation type is DFPT self.read_pattern( @@ -2220,7 +2220,7 @@ def __init__(self, filename: PathLike) -> None: # Check if LEPSILON is True and read piezo data if so self.read_pattern({"epsilon": r"LEPSILON\s*=\s*T"}) - if self.data.get("epsilon", []): + if self.data.get("epsilon", False): self.lepsilon = True self.read_lepsilon() # Only read ionic contribution if DFPT is turned on @@ -2231,7 +2231,7 @@ def __init__(self, filename: PathLike) -> None: # Check if LCALCPOL is True and read polarization data if so self.read_pattern({"calcpol": r"LCALCPOL\s*=\s*T"}) - if self.data.get("calcpol", []): + if self.data.get("calcpol", False): self.lcalcpol = True self.read_lcalcpol() self.read_pseudo_zval() @@ -2243,7 +2243,7 @@ def __init__(self, filename: PathLike) -> None: self.ngf = None self.sampling_radii: list[float] | None = None self.read_pattern({"electrostatic": r"average \(electrostatic\) potential at core"}) - if self.data.get("electrostatic", []): + if self.data.get("electrostatic", False): self.read_electrostatic_potential() self.read_pattern({"nmr_cs": r"LCHIMAG\s*=\s*(T)"})