Skip to content

Commit

Permalink
batch replace 'except:' with 'except Exception:' (#271)
Browse files Browse the repository at this point in the history
The latter will not catch `KeyboardInterrupt` and `SystemExit`. See https://stackoverflow.com/a/18982726/9567349.
  • Loading branch information
njzjz authored Apr 20, 2022
1 parent cf51156 commit f2d3dbd
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dpdata/fhi_aims/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def analyze_block(lines, first_blk=False, md=True) :
contents="\n".join(lines)
try:
natom=int(re.findall("Number of atoms.*([0-9]{1,})",lines)[0])
except:
except Exception:
natom=0

if first_blk:
Expand Down Expand Up @@ -154,7 +154,7 @@ def analyze_block(lines, first_blk=False, md=True) :
try:
_eng_patt=re.compile(eng_patt)
energy=float(_eng_patt.search(contents).group().split()[-2])
except:
except Exception:
energy=None

if not energy:
Expand Down
4 changes: 2 additions & 2 deletions dpdata/rdkit/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_explicit_valence(atom, verbose=False):
print(
f"Explicit valence given by GetExplicitValence() and sum of bond order are inconsistent on {atom.GetSymbol()}{atom.GetIdx() + 1}, using sum of bond order.")
return exp_val_calculated_from_bonds
except:
except Exception:
return exp_val_calculated_from_bonds


Expand All @@ -37,7 +37,7 @@ def regularize_formal_charges(mol, sanitize=True, verbose=False):
try:
Chem.SanitizeMol(mol)
return mol
except:
except Exception:
return None
else:
return mol
Expand Down
2 changes: 1 addition & 1 deletion dpdata/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_unit(unit):
raise RuntimeError(f"Invaild unit: {unit}")
if lunit not in lconvs.keys():
raise RuntimeError(f"Invalid unit: {unit}")
except:
except Exception:
raise RuntimeError(f"Invalid unit: {unit}")

class Conversion(ABC):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pick_atom_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
try:
import parmed
exist_module=True
except:
except Exception:
exist_module=False

class TestPickAtomIdx(unittest.TestCase, CompSys, IsNoPBC):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_to_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ase import Atoms
from ase.io import write
exist_module=True
except:
except Exception:
exist_module=False

@unittest.skipIf(not exist_module,"skip test_ase")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_to_pymatgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
try:
from pymatgen import Structure
exist_module=True
except:
except Exception:
exist_module=False

@unittest.skipIf(not exist_module,"skip pymatgen")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_to_pymatgen_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from pymatgen.entries.computed_entries import ComputedStructureEntry
exist_module=True
except:
except Exception:
exist_module=False

@unittest.skipIf(not exist_module,"skip pymatgen")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_water_ions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ase
import ase.neighborlist
exist_ase=True
except:
except Exception:
exist_ase=False

class TestIons(unittest.TestCase):
Expand Down

0 comments on commit f2d3dbd

Please sign in to comment.