MAINT: Code-hygiene quick wins (#882) - #964
Conversation
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.
|
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: ( 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 |
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 frommain, so nothing was needed there. The rest are addressed:2. Bare
exceptaround the numba import (quantecon/__init__.py)except:caughtKeyboardInterruptandSystemExitduring import and discarded the original exception, then raised a conda-only message. Nowexcept 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 originalImportError.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:246isinstance(...) == Trueto a plainisinstance,_dle.py:280andutil/notebooks.py:89type(x) != np.ndarray/type(x) == listtoisinstance. 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 toquantecon/tests/since the issue was written; the line number in the issue still matches.6. Unused
__exit__bindings and the loneimport *util/timing.pybinds none ofexc_type,exc_val,exc_tb, so the signature is now*exc_info.Timerstill propagates exceptions unchanged, since it never suppressed them.game_theory/game_generators/__init__.pynow imports the five generators explicitly and declares__all__, so its# flake8: noqacould go. The exported names are identical to what the star import produced.Checks
Acceptance criterion, before and after, on
4cbe3bb:The CI selects (
flake8 --select=F401,F405,E231 quantecon) stay clean, which is what the removednoqahad to be checked against.Full suite on Python 3.13.9, NumPy 2.3.5, numba 0.62.1, macOS: 730 passed on
4cbe3bband 730 passed with this change.No behaviour change is intended anywhere. The
isinstanceconversions widen two checks to acceptndarrayandlistsubclasses, which is the point of usingisinstance, and no caller in the package passes one today.Fixes #882