Skip to content

Commit f2d3dbd

Browse files
authored
batch replace 'except:' with 'except Exception:' (#271)
The latter will not catch `KeyboardInterrupt` and `SystemExit`. See https://stackoverflow.com/a/18982726/9567349.
1 parent cf51156 commit f2d3dbd

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

dpdata/fhi_aims/output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def analyze_block(lines, first_blk=False, md=True) :
124124
contents="\n".join(lines)
125125
try:
126126
natom=int(re.findall("Number of atoms.*([0-9]{1,})",lines)[0])
127-
except:
127+
except Exception:
128128
natom=0
129129

130130
if first_blk:
@@ -154,7 +154,7 @@ def analyze_block(lines, first_blk=False, md=True) :
154154
try:
155155
_eng_patt=re.compile(eng_patt)
156156
energy=float(_eng_patt.search(contents).group().split()[-2])
157-
except:
157+
except Exception:
158158
energy=None
159159

160160
if not energy:

dpdata/rdkit/sanitize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_explicit_valence(atom, verbose=False):
2222
print(
2323
f"Explicit valence given by GetExplicitValence() and sum of bond order are inconsistent on {atom.GetSymbol()}{atom.GetIdx() + 1}, using sum of bond order.")
2424
return exp_val_calculated_from_bonds
25-
except:
25+
except Exception:
2626
return exp_val_calculated_from_bonds
2727

2828

@@ -37,7 +37,7 @@ def regularize_formal_charges(mol, sanitize=True, verbose=False):
3737
try:
3838
Chem.SanitizeMol(mol)
3939
return mol
40-
except:
40+
except Exception:
4141
return None
4242
else:
4343
return mol

dpdata/unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def check_unit(unit):
3535
raise RuntimeError(f"Invaild unit: {unit}")
3636
if lunit not in lconvs.keys():
3737
raise RuntimeError(f"Invalid unit: {unit}")
38-
except:
38+
except Exception:
3939
raise RuntimeError(f"Invalid unit: {unit}")
4040

4141
class Conversion(ABC):

tests/test_pick_atom_idx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
try:
66
import parmed
77
exist_module=True
8-
except:
8+
except Exception:
99
exist_module=False
1010

1111
class TestPickAtomIdx(unittest.TestCase, CompSys, IsNoPBC):

tests/test_to_ase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ase import Atoms
88
from ase.io import write
99
exist_module=True
10-
except:
10+
except Exception:
1111
exist_module=False
1212

1313
@unittest.skipIf(not exist_module,"skip test_ase")

tests/test_to_pymatgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
try:
77
from pymatgen import Structure
88
exist_module=True
9-
except:
9+
except Exception:
1010
exist_module=False
1111

1212
@unittest.skipIf(not exist_module,"skip pymatgen")

tests/test_to_pymatgen_entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try:
88
from pymatgen.entries.computed_entries import ComputedStructureEntry
99
exist_module=True
10-
except:
10+
except Exception:
1111
exist_module=False
1212

1313
@unittest.skipIf(not exist_module,"skip pymatgen")

tests/test_water_ions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import ase
77
import ase.neighborlist
88
exist_ase=True
9-
except:
9+
except Exception:
1010
exist_ase=False
1111

1212
class TestIons(unittest.TestCase):

0 commit comments

Comments
 (0)