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"] 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..fbd658b45 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 isinstance(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}")