From 17855fe36c8f699273ca7b885742fabf26dbeddd Mon Sep 17 00:00:00 2001 From: Shyue Ping Ong Date: Fri, 25 Oct 2024 08:26:50 -0700 Subject: [PATCH] Reduce code duplication. --- src/pymatgen/io/vasp/outputs.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pymatgen/io/vasp/outputs.py b/src/pymatgen/io/vasp/outputs.py index 331ea5b6c24..470b5c5c29c 100644 --- a/src/pymatgen/io/vasp/outputs.py +++ b/src/pymatgen/io/vasp/outputs.py @@ -5803,18 +5803,16 @@ def __init__(self, dirname: str | Path): dirname: The directory containing the VASP calculation as a string or Path. """ self.path = Path(dirname).absolute() - - # Note that py3.12 has Path.walk(). But we need to use os.walk to ensure backwards compatibility for now. - self.files = [str(Path(d) / f).lstrip(str(self.path)) for d, _, fnames in os.walk(self.path) for f in fnames] - self._parsed_files: dict[str, Any] = {} + self.reset() def reset(self): """ Reset all loaded files and recheck the directory for files. Use this when the contents of the directory has changed. """ + # Note that py3.12 has Path.walk(). But we need to use os.walk to ensure backwards compatibility for now. self.files = [str(Path(d) / f).lstrip(str(self.path)) for d, _, fnames in os.walk(self.path) for f in fnames] - self._parsed_files = {} + self._parsed_files: dict[str, Any] = {} def __len__(self): return len(self.files)