public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 9/9] Do not use bare "except"
Date: Tue, 19 Mar 2024 11:33:37 -0600	[thread overview]
Message-ID: <20240319-more-flake8-v1-9-893549dbed75@adacore.com> (raw)
In-Reply-To: <20240319-more-flake8-v1-0-893549dbed75@adacore.com>

flake8 warns about a bare "except".  The docs point out that this will
also catch KeyboardInterrupt and SystemExit exceptions, which is
normally undesirable.  Using "except Exception" catches everything
reasonable, so this patch makes this change.
---
 gdb/python/lib/gdb/__init__.py | 2 +-
 gdb/python/lib/gdb/styling.py  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index cff2f3afa49..e7d21fe8d27 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -157,7 +157,7 @@ def _auto_load_packages():
                         reload(__import__(modname))
                     else:
                         __import__(modname)
-                except:
+                except Exception:
                     sys.stderr.write(traceback.format_exc() + "\n")
 
 
diff --git a/gdb/python/lib/gdb/styling.py b/gdb/python/lib/gdb/styling.py
index 704c9926c29..8e5d64f15d9 100644
--- a/gdb/python/lib/gdb/styling.py
+++ b/gdb/python/lib/gdb/styling.py
@@ -39,7 +39,7 @@ try:
             return highlight(contents, lexer, formatter).encode(
                 gdb.host_charset(), "backslashreplace"
             )
-        except:
+        except Exception:
             return None
 
     class HandleNasmComments(TokenMergeFilter):
@@ -70,7 +70,7 @@ try:
             flavor = gdb.parameter("disassembly-flavor")
             if flavor == "intel" and gdbarch.name()[:4] == "i386":
                 lexer_type = "nasm"
-        except:
+        except Exception:
             # If GDB is built without i386 support then attempting to fetch
             # the 'disassembly-flavor' parameter will throw an error, which we
             # ignore.
@@ -89,7 +89,7 @@ try:
             lexer = __get_asm_lexer(gdbarch)
             formatter = get_formatter()
             return highlight(content, lexer, formatter).rstrip().encode()
-        except:
+        except Exception:
             return content
 
 except ImportError:

-- 
2.43.0


  parent reply	other threads:[~2024-03-19 17:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 17:33 [PATCH 0/9] Make gdb/python flake-clean Tom Tromey
2024-03-19 17:33 ` [PATCH 1/9] Remove .flake8 Tom Tromey
2024-03-19 17:33 ` [PATCH 2/9] Fix flake8 errors in dap/server.py Tom Tromey
2024-03-19 17:33 ` [PATCH 3/9] Ignore unsed import in dap/__init__.py Tom Tromey
2024-03-20 15:35   ` Tom Tromey
2024-03-19 17:33 ` [PATCH 4/9] Remove unused import from gdb/__init__.py Tom Tromey
2024-03-19 17:33 ` [PATCH 5/9] Remove bare "except" from disassembler.py Tom Tromey
2024-03-19 17:33 ` [PATCH 6/9] Suppress star import errors Tom Tromey
2024-03-19 17:33 ` [PATCH 7/9] Specify ImportError in styling.py Tom Tromey
2024-03-19 17:33 ` [PATCH 8/9] Suppress some "undefined" warnings from flake8 Tom Tromey
2024-03-20 18:58   ` Simon Marchi
2024-03-20 20:30     ` Tom Tromey
2024-03-20 20:32       ` Tom Tromey
2024-03-19 17:33 ` Tom Tromey [this message]
2024-03-20 19:01 ` [PATCH 0/9] Make gdb/python flake-clean Simon Marchi
2024-04-02 17:01 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319-more-flake8-v1-9-893549dbed75@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).