Skip to content

MAINT: Code-hygiene quick wins (#882) - #964

Open
jadhavgaurav wants to merge 1 commit into
QuantEcon:mainfrom
jadhavgaurav:maint/code-hygiene-882
Open

MAINT: Code-hygiene quick wins (#882)#964
jadhavgaurav wants to merge 1 commit into
QuantEcon:mainfrom
jadhavgaurav:maint/code-hygiene-882

Conversation

@jadhavgaurav

Copy link
Copy Markdown

Fixes the code-hygiene items from the July 2026 technical-debt audit.

Item 1 of the issue (quantecon/util/common_messages.py) is already gone from main, so nothing was needed there. The rest are addressed:

2. Bare except around the numba import (quantecon/__init__.py)
except: caught KeyboardInterrupt and SystemExit during import and discarded the original exception, then raised a conda-only message. Now except ImportError as e: ... from e, with a message that names both pip and conda. The original traceback survives, which matters for the common numba/llvmlite ABI-mismatch case. Verified by blocking the numba import in a subprocess: the new message is raised and __cause__ is the original ImportError.

3. Dead __main__ block (quantecon/tests/test_quadsum.py)
The nose-era block called three undefined names and left a fourth uncalled, so running the file directly raised NameError. It was the source of all three F821s in the package. Deleted.

4. Comparison anti-patterns
_dle.py:246 isinstance(...) == True to a plain isinstance, _dle.py:280 and util/notebooks.py:89 type(x) != np.ndarray / type(x) == list to isinstance. Deeper DLE work stays in #844.

5. Bare except (quantecon/tests/test_graph_tools.py:137)
Now except KeyError:, which is the only thing a missing 'weighted' key can raise there. The file moved to quantecon/tests/ since the issue was written; the line number in the issue still matches.

6. Unused __exit__ bindings and the lone import *
util/timing.py binds none of exc_type, exc_val, exc_tb, so the signature is now *exc_info. Timer still propagates exceptions unchanged, since it never suppressed them. game_theory/game_generators/__init__.py now imports the five generators explicitly and declares __all__, so its # flake8: noqa could go. The exported names are identical to what the star import produced.

Checks

Acceptance criterion, before and after, on 4cbe3bb:

$ flake8 --select=F821,E722,E712,E721 quantecon
# before: 7 violations (E712, E721 x2, E722, F821 x3)
# after:  clean

The CI selects (flake8 --select=F401,F405,E231 quantecon) stay clean, which is what the removed noqa had to be checked against.

Full suite on Python 3.13.9, NumPy 2.3.5, numba 0.62.1, macOS: 730 passed on 4cbe3bb and 730 passed with this change.

No behaviour change is intended anywhere. The isinstance conversions widen two checks to accept ndarray and list subclasses, which is the point of using isinstance, and no caller in the package passes one today.

Fixes #882

Address the remaining items of the July 2026 audit's hygiene list. Item 1
(common_messages.py) is already gone from main.

- quantecon/__init__.py: the bare except around the numba import caught
  KeyboardInterrupt and SystemExit and dropped the original exception. Catch
  ImportError, chain it with "from e", and name pip as well as conda.
- tests/test_quadsum.py: drop the nose-era __main__ block. It called three
  undefined names and was the source of every F821 in the package.
- _dle.py, util/notebooks.py: replace "isinstance(...) == True" and
  "type(x) == list" / "type(x) != np.ndarray" with plain isinstance checks.
- tests/test_graph_tools.py: bare except becomes except KeyError.
- util/timing.py: Timer.__exit__ binds none of its three arguments, so take
  *exc_info instead.
- game_theory/game_generators/__init__.py: import the five generators
  explicitly and declare __all__, which lets the file drop its flake8 noqa.
  The exported names are unchanged.

flake8 --select=F821,E722,E712,E721 quantecon goes from 7 violations to none.
No behaviour change intended.

Copy link
Copy Markdown
Collaborator

Hi @jadhavgaurav — a quick process note while this is in the review queue.

QuantEcon's Code of AI Use (QEP-5, QuantEcon/qeps#13) doesn't restrict AI-assisted contributions, but it does ask that meaningful AI involvement be disclosed. We'd like it in two places: a trailer in the commit message, and a one-line note in the PR description.

If AI tools were involved here, please add the trailer:

Assisted-by: <tool name>

(git commit --amend, then force-push the branch.) And add a line to the PR description saying which tools were used and for what. If the work was entirely hand-written, a quick note here saying so is equally useful.

The intent is that reviewers know what to expect, and that a human has chosen the task, checked the result, and will own the follow-up discussion.


Generated by Claude Code

@mmcky mmcky added the author-response Waiting on author response label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author-response Waiting on author response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT: Code-hygiene quick wins: dead code, bare excepts, broken test block, comparison anti-patterns

3 participants