Skip to content

Commit

Permalink
Enable check for bare 'except' blocks (E722) (senaite#2100)
Browse files Browse the repository at this point in the history
* Enable check for bare 'except' blocks (E722)

* Remove unnecessary noqa statements
  • Loading branch information
winniehell authored Aug 6, 2022
1 parent ddc039e commit dc1c365
Show file tree
Hide file tree
Showing 58 changed files with 80 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/bika/lims/browser/analysisservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __call__(self):
try:
minvol = minvol.split()
minvol = mg(float(minvol[0]), " ".join(minvol[1:]))
except:
except Exception:
minvol = mg(0)

containers = getContainers(
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/browser/widgets/rejectionwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

try:
from zope.component.hooks import getSite
except:
except Exception:
# Plone < 4.3
from zope.app.component.hooks import getSite

Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/browser/worksheet/views/printview.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def renderWSTemplate(self):
reptemplate = ""
try:
reptemplate = embed(self)
except:
except Exception:
tbex = traceback.format_exc()
wsid = self._worksheets[self._current_ws_index].id
reptemplate = "<div class='error-print'>%s - %s '%s':<pre>%s</pre></div>" % (wsid, _("Unable to load the template"), embedt, tbex)
Expand Down
6 changes: 2 additions & 4 deletions src/bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,10 +1828,9 @@ def getVerifier(self):
mtool = getToolByName(self, 'portal_membership')

verifier = None
# noinspection PyBroadException
try:
review_history = wtool.getInfoFor(self, 'review_history')
except: # noqa FIXME: remove blind except!
except Exception:
return 'access denied'

if not review_history:
Expand Down Expand Up @@ -2114,10 +2113,9 @@ def getRejecter(self):
"""
wtool = getToolByName(self, 'portal_workflow')
mtool = getToolByName(self, 'portal_membership')
# noinspection PyBroadException
try:
review_history = wtool.getInfoFor(self, 'review_history')
except: # noqa FIXME: remove blind except!
except Exception:
return None
for items in review_history:
action = items.get('action')
Expand Down
6 changes: 3 additions & 3 deletions src/bika/lims/content/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ def getJSCapacity(self, **kw):
try:
mgdefault = default.split(' ', 1)
mgdefault = mg(float(mgdefault[0]), mgdefault[1])
except:
except Exception:
mgdefault = mg(0, 'ml')
try:
return str(mgdefault.ounit('ml'))
except:
except Exception:
pass
try:
return str(mgdefault.ounit('g'))
except:
except Exception:
pass
return str(default)

Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/content/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def addReferences(self, reference, service_uids):
cand = int(grid.split('-')[2])
if cand >= postfix:
postfix = cand + 1
except:
except Exception:
pass
postfix = str(postfix).zfill(int(3))
refgid = 'I%s-%s' % (reference.id, postfix)
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/content/labproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def getVATAmount(self):
"""
try:
vatamount = self.getTotalPrice() - Decimal(self.getPrice())
except:
except Exception:
vatamount = Decimal('0.00')
return vatamount.quantize(Decimal('0.00'))

Expand Down
6 changes: 3 additions & 3 deletions src/bika/lims/content/sampletype.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ def getJSMinimumVolume(self, **kw):
try:
mgdefault = default.split(' ', 1)
mgdefault = mg(float(mgdefault[0]), mgdefault[1])
except:
except Exception:
mgdefault = mg(0, 'ml')
try:
return str(mgdefault.ounit('ml'))
except:
except Exception:
pass
try:
return str(mgdefault.ounit('g'))
except:
except Exception:
pass
return str(default)

Expand Down
6 changes: 3 additions & 3 deletions src/bika/lims/jsonapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def load_brain_metadata(proxy, include_fields):
if val != Missing.Value:
try:
json.dumps(val)
except:
except Exception:
continue
ret[index] = val
return ret
Expand Down Expand Up @@ -128,7 +128,7 @@ def load_field_values(instance, include_fields):

try:
json.dumps(val)
except:
except Exception:
val = str(val)
ret[fieldname] = val
return ret
Expand Down Expand Up @@ -238,7 +238,7 @@ def set_fields_from_request(obj, request):
'senaite.core.browser.fields.record.RecordField']:
try:
value = eval(value)
except:
except Exception:
logger.warning(
"JSONAPI: " + fieldname + ": Invalid "
"JSON/Python variable")
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/jsonapi/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def create(self, context, request):
obj.aq_parent.reindexObject()
event.notify(ObjectInitializedEvent(obj))
obj.at_post_create_script()
except:
except Exception:
savepoint.rollback()
raise

Expand Down
4 changes: 2 additions & 2 deletions src/bika/lims/jsonapi/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def update(self, context, request):
return ret
for field in fields:
self.used(field)
except:
except Exception:
savepoint.rollback()
raise

Expand Down Expand Up @@ -238,7 +238,7 @@ def update_many(self, context, request):
else:
this_ret['success'] = True
this_ret['error'] = False
except:
except Exception:
savepoint.rollback()
raise
ret['updates'].append(this_ret)
Expand Down
4 changes: 2 additions & 2 deletions src/bika/lims/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def formatDecimalMark(value, decimalmark='.'):
rawval = str(value)
try:
return decimalmark.join(rawval.split('.'))
except:
except Exception:
return rawval


Expand Down Expand Up @@ -479,7 +479,7 @@ def getHiddenAttributesForClass(classname):
for alist in hiddenattributes:
if alist[0] == classname:
return alist[1:]
except:
except Exception:
logger.warning(
'Probem accessing optionally hidden attributes in registry')

Expand Down
6 changes: 3 additions & 3 deletions src/bika/lims/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def __call__(self, value, *args, **kwargs):
for v in value.values():
try:
int(v)
except:
except Exception:
return to_utf8(
translate(_("Validation failed: Values must be numbers")))
return True
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def __call__(self, value, *args, **kwargs):

try:
value = float(value)
except:
except Exception:
msg = _("Validation failed: percent values must be numbers")
return to_utf8(translate(msg))

Expand Down Expand Up @@ -1329,7 +1329,7 @@ def __call__(self, value, *args, **kwargs):
translate = getToolByName(instance, 'translation_service').translate
try:
value = float(value)
except:
except Exception:
msg = _("Validation failed: value must be float")
return to_utf8(translate(msg))

Expand Down
4 changes: 2 additions & 2 deletions src/senaite/core/browser/fields/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def set(self, instance, value, **kwargs):
try:
value = eval(value)
# more checks to add?
except: # what to catch here?
except Exception: # what to catch here?
pass
value = self._to_dict(value)
value = self._decode_strings(value, instance, **kwargs)
Expand All @@ -262,7 +262,7 @@ def _decode_strings(self, value, instance, **kwargs):
if self.subfield_types.get(k, None) == 'datetime':
try:
val = DateTime(v)
except:
except Exception:
val = None

new_value[k] = val
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def Import(context, request):
try:
# run the parser and save results
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def Import( context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down Expand Up @@ -143,7 +143,7 @@ def _addRawResult(self, resid, values={}, override=False):
from datetime import datetime
dtobj = datetime.strptime(dtstr, '%d/%m/%Y %H:%M %p')
dateTime = dtobj.strftime("%Y%m%d %H:%M")
except:
except Exception:
pass
del values['Date']
del values['Time']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __call__(self, context, request):
exception_string = ''
try:
importer.process()
except:
except Exception:
exception_string = traceback.format_exc()
self.errors = importer.errors
self.logs = importer.logs
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/core/exportimport/instruments/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def GenericImport(context, request, parser, importer=None):
tbex = ''
try:
imp.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = imp.errors
logs = imp.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def Import(context, request):
tbex = ''
try:
importer.process()
except:
except Exception:
tbex = traceback.format_exc()
errors = importer.errors
logs = importer.logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _parseline(self, line):
dtstr = '%s %s' % (_values['Date'], _values['Time'])
dtobj = datetime.strptime(dtstr, '%Y/%m/%d %H:%M %p')
values[self.analysiskey]['DateTime'] = dtobj.strftime("%Y%m%d %H:%M:%S")
except:
except Exception:
pass

# add result
Expand Down
Loading

0 comments on commit dc1c365

Please sign in to comment.