# HG changeset patch # User John Rouillard # Date 1772117162 18000 # Node ID fed0f839c26062bca99304a0198a17cf21554915 # Parent d4a43d9da8ef4282e4d5b107296ec45d2de5b555 fix: replace except: with except Exception: (by haosenwang1018@github) Remove bare 'except:' statements replace with 'except Exception'. In roundup_xmlrpc_server.py I changed Exception to BaseException so the database gets closed on signals as well. The rest of the changes do not look like they affect data integrity and are commited as supplied. diff -r d4a43d9da8ef -r fed0f839c260 CHANGES.txt --- a/CHANGES.txt Mon Feb 23 20:16:55 2026 -0500 +++ b/CHANGES.txt Thu Feb 26 09:46:02 2026 -0500 @@ -45,6 +45,8 @@ into Client(). (John Rouillard) - issue2551393 - Named searches lose their name in title when next page is selected. (John Rouillard) +- code cleanup replace bare except: with except Exception:. (patch by + Sense_wang (haosenwang1018) applied by John Rouillard) Features: diff -r d4a43d9da8ef -r fed0f839c260 frontends/ZRoundup/ZRoundup.py --- a/frontends/ZRoundup/ZRoundup.py Mon Feb 23 20:16:55 2026 -0500 +++ b/frontends/ZRoundup/ZRoundup.py Thu Feb 26 09:46:02 2026 -0500 @@ -210,7 +210,7 @@ except client.NotFound: raise Exception('NotFound ' + REQUEST.URL) pass - except: + except Exception: import traceback traceback.print_exc() # all other exceptions in roundup are valid diff -r d4a43d9da8ef -r fed0f839c260 roundup/anypy/vendored/cgi.py --- a/roundup/anypy/vendored/cgi.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/anypy/vendored/cgi.py Thu Feb 26 09:46:02 2026 -0500 @@ -870,7 +870,7 @@ f() print("

What follows is a test, not an actual exception:

") g() - except: + except Exception: print_exception() print("

Second try with a small maxlen...

") @@ -883,7 +883,7 @@ print_arguments() print_form(form) print_environ(environ) - except: + except Exception: print_exception() def print_exception(type=None, value=None, tb=None, limit=None): diff -r d4a43d9da8ef -r fed0f839c260 roundup/backends/rdbms_common.py --- a/roundup/backends/rdbms_common.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/backends/rdbms_common.py Thu Feb 26 09:46:02 2026 -0500 @@ -2612,7 +2612,7 @@ e.context['class'] = pln e.context['attr'] = prp raise - except: + except Exception: pass # Fallback to original code args = [] @@ -2693,7 +2693,7 @@ e.context['class'] = classname e.context['attr'] = proptree.name raise - except: + except Exception: # fallback behavior when expression parsing above fails orclause = '' if '-1' in v: diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/PageTemplates/PageTemplate.py --- a/roundup/cgi/PageTemplates/PageTemplate.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/PageTemplates/PageTemplate.py Thu Feb 26 09:46:02 2026 -0500 @@ -106,7 +106,7 @@ if not self.expand: return try: self.pt_render(source=1) - except: + except Exception: return ('Macro expansion failed', '%s: %s' % sys.exc_info()[:2]) def pt_warnings(self): @@ -147,7 +147,7 @@ return self._text try: return self.pt_render(source=1) - except: + except Exception: return ('%s\n Macro expansion failed\n %s\n-->\n%s' % (self._error_start, "%s: %s" % sys.exc_info()[:2], self._text) ) @@ -177,7 +177,7 @@ try: parser.parseString(self._text) self._v_program, self._v_macros = parser.getCode() - except: + except Exception: self._v_errors = ["Compilation failed", "%s: %s" % sys.exc_info()[:2]] self._v_warnings = parser.getWarnings() diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/PageTemplates/PythonExpr.py --- a/roundup/cgi/PageTemplates/PythonExpr.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/PageTemplates/PythonExpr.py Thu Feb 26 09:46:02 2026 -0500 @@ -36,7 +36,7 @@ self.f_code = 'def f():\n return %s\n' % expr.strip() exec(self.f_code, d) self._f = d['f'] - except: + except Exception: raise CompilerError(('Python expression error:\n' '%s: %s') % exc_info()[:2]) self._get_used_names() diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/TAL/DummyEngine.py --- a/roundup/cgi/TAL/DummyEngine.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/TAL/DummyEngine.py Thu Feb 26 09:46:02 2026 -0500 @@ -118,7 +118,7 @@ if type == "python": try: return eval(expr, self.globals, self.locals) - except: + except Exception: raise TALESError("evaluation error in %s" % repr(expr)) if type == "position": # Insert the current source file name, line number, diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/TAL/TALInterpreter.py --- a/roundup/cgi/TAL/TALInterpreter.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/TAL/TALInterpreter.py Thu Feb 26 09:46:02 2026 -0500 @@ -724,7 +724,7 @@ self._stream_write = stream.write try: self.interpret(block) - except: + except Exception: exc = sys.exc_info()[1] self.restoreState(state) engine = self.engine diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/ZTUtils/Iterator.py --- a/roundup/cgi/ZTUtils/Iterator.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/ZTUtils/Iterator.py Thu Feb 26 09:46:02 2026 -0500 @@ -189,7 +189,7 @@ try: if hasattr(ob, 'next') and (ob is iter(ob)): return 1 - except: + except Exception: return 0 def prep_next(self, it): diff -r d4a43d9da8ef -r fed0f839c260 roundup/cgi/templating.py --- a/roundup/cgi/templating.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/cgi/templating.py Thu Feb 26 09:46:02 2026 -0500 @@ -2717,7 +2717,7 @@ # ignore these errors to preserve user input try: display_value.sort(key=keyfun) - except: + except Exception: pass self._value = display_value diff -r d4a43d9da8ef -r fed0f839c260 roundup/dist/command/build.py --- a/roundup/dist/command/build.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/dist/command/build.py Thu Feb 26 09:46:02 2026 -0500 @@ -30,7 +30,7 @@ manifest_file = 'roundup.egg-info/SOURCES.txt' try: f=open(manifest_file) - except: + except Exception: print('\n*** SOURCE WARNING: The MANIFEST file "%s" is missing!' % manifest_file) return try: diff -r d4a43d9da8ef -r fed0f839c260 roundup/scripts/roundup_xmlrpc_server.py --- a/roundup/scripts/roundup_xmlrpc_server.py Mon Feb 23 20:16:55 2026 -0500 +++ b/roundup/scripts/roundup_xmlrpc_server.py Thu Feb 26 09:46:02 2026 -0500 @@ -105,7 +105,7 @@ SimpleXMLRPCRequestHandler.do_POST(self) except Unauthorised as message: self.send_error(403, '%s (%s)' % (self.path, message)) - except: + except BaseException: if db: db.close() exc, val, tb = sys.exc_info() diff -r d4a43d9da8ef -r fed0f839c260 scripts/copy-user.py --- a/scripts/copy-user.py Mon Feb 23 20:16:55 2026 -0500 +++ b/scripts/copy-user.py Thu Feb 26 09:46:02 2026 -0500 @@ -31,14 +31,14 @@ try: instance1 = roundup.instance.open(home1) print("Opened source instance: %s" % home1) - except: + except Exception: print("Can't open source instance: %s" % home1) sys.exit(1) try: instance2 = roundup.instance.open(home2) print("Opened target instance: %s" % home2) - except: + except Exception: print("Can't open target instance: %s" % home2) sys.exit(1) diff -r d4a43d9da8ef -r fed0f839c260 scripts/imapServer.py --- a/scripts/imapServer.py Mon Feb 23 20:16:55 2026 -0500 +++ b/scripts/imapServer.py Thu Feb 26 09:46:02 2026 -0500 @@ -225,7 +225,7 @@ # We are done with this mailbox serv.close() - except: + except Exception: log.exception('Exception with server %s user %s', server, user) noErrors = False @@ -233,7 +233,7 @@ serv.logout() serv.shutdown() del serv - except: + except Exception: log.exception('Exception while connecting to %s', server) noErrors = False return noErrors diff -r d4a43d9da8ef -r fed0f839c260 scripts/import_sf.py --- a/scripts/import_sf.py Mon Feb 23 20:16:55 2026 -0500 +++ b/scripts/import_sf.py Thu Feb 26 09:46:02 2026 -0500 @@ -299,7 +299,7 @@ f = open(os.path.join(file_dir, fid), 'rb') content = f.read() f.close() - except: + except Exception: content = 'content missing' file_data.append({ 'id': fid, diff -r d4a43d9da8ef -r fed0f839c260 test/test_locking.py --- a/test/test_locking.py Mon Feb 23 20:16:55 2026 -0500 +++ b/test/test_locking.py Thu Feb 26 09:46:02 2026 -0500 @@ -33,7 +33,7 @@ f = acquire_lock(self.path) try: acquire_lock(self.path, block=0) - except: + except Exception: pass else: raise AssertionError('no exception') diff -r d4a43d9da8ef -r fed0f839c260 tools/load_tracker.py --- a/tools/load_tracker.py Mon Feb 23 20:16:55 2026 -0500 +++ b/tools/load_tracker.py Thu Feb 26 09:46:02 2026 -0500 @@ -55,7 +55,7 @@ try: try: db.user.lookup('alpha0') - except: + except Exception: # add some users M = N//100 for i in range(M): diff -r d4a43d9da8ef -r fed0f839c260 tools/migrate-queries.py --- a/tools/migrate-queries.py Mon Feb 23 20:16:55 2026 -0500 +++ b/tools/migrate-queries.py Thu Feb 26 09:46:02 2026 -0500 @@ -22,7 +22,7 @@ # Do some basic exception handling to catch bad arguments. try: instance = roundup.instance.open(home) - except: + except Exception: print('Cannot open instance home directory %s!' % home) continue