From e21804165ae3d3fd72f06d4b513cff9ee7fa5953 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 05:26:47 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.0.282 → v0.0.284](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.282...v0.0.284) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7b7fb84d3..fe362cb0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: black-jupyter - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.0.282 + rev: v0.0.284 hooks: - id: ruff args: ["--fix"] From 6ef2524ad47412498f303d54944371e521d8ad7d Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 15 Aug 2023 15:59:06 -0400 Subject: [PATCH 2/3] fix E721 Do not compare types, use `isinstance()` --- dpdata/abacus/md.py | 2 +- dpdata/abacus/relax.py | 2 +- dpdata/abacus/scf.py | 6 +++--- dpdata/qe/scf.py | 4 ++-- dpdata/system.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 8cda59608..55538d0b1 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -148,7 +148,7 @@ def get_energy(outlines, ndump, dump_freq): def get_frame(fname): - if type(fname) == str: + if isinstance(fname, str): # if the input parameter is only one string, it is assumed that it is the # base directory containing INPUT file; path_in = os.path.join(fname, "INPUT") diff --git a/dpdata/abacus/relax.py b/dpdata/abacus/relax.py index 5dd77030b..db910fc7e 100644 --- a/dpdata/abacus/relax.py +++ b/dpdata/abacus/relax.py @@ -167,7 +167,7 @@ def get_coords_from_log(loglines, natoms): def get_frame(fname): - if type(fname) == str: + if isinstance(fname, str): # if the input parameter is only one string, it is assumed that it is the # base directory containing INPUT file; path_in = os.path.join(fname, "INPUT") diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index d6f83e72a..1cf2cd2da 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -161,7 +161,7 @@ def get_frame(fname): "forces": [], } - if type(fname) == str: + if isinstance(fname, str): # if the input parameter is only one string, it is assumed that it is the # base directory containing INPUT file; path_in = os.path.join(fname, "INPUT") @@ -255,7 +255,7 @@ def get_nele_from_stru(geometry_inlines): def get_frame_from_stru(fname): - assert type(fname) == str + assert isinstacne(fname, str) with open(fname) as fp: geometry_inlines = fp.read().split("\n") nele = get_nele_from_stru(geometry_inlines) @@ -304,7 +304,7 @@ def make_unlabeled_stru( out += "\n" if numerical_descriptor is not None: - assert type(numerical_descriptor) == str + assert isinstance(numerical_descriptor, str) out += "NUMERICAL_DESCRIPTOR\n%s\n" % numerical_descriptor out += "\n" diff --git a/dpdata/qe/scf.py b/dpdata/qe/scf.py index 4457572d0..d2f5dead4 100755 --- a/dpdata/qe/scf.py +++ b/dpdata/qe/scf.py @@ -129,13 +129,13 @@ def get_stress(lines): def get_frame(fname): - if type(fname) == str: + if isinstance(fname, str): path_out = fname outname = os.path.basename(path_out) # the name of the input file is assumed to be different from the output by 'in' and 'out' inname = outname.replace("out", "in") path_in = os.path.join(os.path.dirname(path_out), inname) - elif type(fname) == list and len(fname) == 2: + elif isinstance(fname, list) and len(fname) == 2: path_in = fname[0] path_out = fname[1] else: diff --git a/dpdata/system.py b/dpdata/system.py index 171cd81a6..8bd91cd98 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -654,7 +654,7 @@ def replicate(self, ncopy): if len(ncopy) != 3: raise RuntimeError("ncopy must be a list or tuple with 3 int") for ii in ncopy: - if type(ii) is not int: + if not isinstance(ii, int): raise RuntimeError("ncopy must be a list or tuple must with 3 int") tmp = System() @@ -690,7 +690,7 @@ def replace(self, initial_atom_type, end_atom_type, replace_num): raise RuntimeError( "Must use method replace() of the instance of class dpdata.System" ) - if type(replace_num) is not int: + if not isinstance(replace_num, int): raise ValueError(f"replace_num must be a integer. Now is {replace_num}") if replace_num <= 0: raise ValueError(f"replace_num must be larger than 0.Now is {replace_num}") From 61ad06387ce3df2a9fd04a64a4cece2f3f5715ff Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 15 Aug 2023 16:13:19 -0400 Subject: [PATCH 3/3] fix typo --- dpdata/abacus/scf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index 1cf2cd2da..fbd658b45 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -255,7 +255,7 @@ def get_nele_from_stru(geometry_inlines): def get_frame_from_stru(fname): - assert isinstacne(fname, str) + assert isinstance(fname, str) with open(fname) as fp: geometry_inlines = fp.read().split("\n") nele = get_nele_from_stru(geometry_inlines)