Skip to content

fix: replace bare except clauses with except Exception in inspection.py - #1056

Open
koteshyelamati wants to merge 1 commit into
bpython:mainfrom
koteshyelamati:main
Open

fix: replace bare except clauses with except Exception in inspection.py#1056
koteshyelamati wants to merge 1 commit into
bpython:mainfrom
koteshyelamati:main

Conversation

@koteshyelamati

Copy link
Copy Markdown

Summary

Replace two bare except: clauses in bpython/inspection.py with except Exception:.

Changes

Line 272getattr(f, "__name__", None) can raise if the object has a descriptor that throws:

# Before
except:

# After
except Exception:

Line 282 — comment notes this catches xmlrpclib.Fault, which is an Exception subclass (see issue #202):

# Before
except:

# After
except Exception:

Why

Bare except: catches BaseException, including SystemExit and KeyboardInterrupt. All exceptions thrown here are Exception subclasses, so except Exception: is correct and safer.

@sebastinas

sebastinas commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

getattr may run arbitrary code from the user (via the object's __getattribute__) which may throw arbitrary exceptions. So in the first instance we definitely want to catch everything.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.04%. Comparing base (1a919d3) to head (e5aecf2).
⚠️ Report is 47 commits behind head on main.

Files with missing lines Patch % Lines
bpython/inspection.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1056      +/-   ##
==========================================
- Coverage   76.51%   76.04%   -0.48%     
==========================================
  Files          62       61       -1     
  Lines        8308     8261      -47     
==========================================
- Hits         6357     6282      -75     
- Misses       1951     1979      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants