Skip to content

fix: replace bare except blocks, deprecated logging.warn, dead code, and mutable default#271

Open
haoyu-haoyu wants to merge 1 commit intoneurolib-dev:masterfrom
haoyu-haoyu:fix/code-quality-bugs
Open

fix: replace bare except blocks, deprecated logging.warn, dead code, and mutable default#271
haoyu-haoyu wants to merge 1 commit intoneurolib-dev:masterfrom
haoyu-haoyu:fix/code-quality-bugs

Conversation

@haoyu-haoyu
Copy link
Copy Markdown

Summary

  • Replace bare except: with except Exception: in utils/functions.py (fcd()) and optimize/evolution/evolutionaryUtils.py (saveToPypet()). Bare except: catches KeyboardInterrupt and SystemExit, preventing users from interrupting long-running simulations.

  • Replace deprecated logging.warn() with logging.warning() in models/model.py (3 occurrences) and evolutionaryUtils.py (1 occurrence). logging.warn() has been deprecated since Python 3.3.

  • Remove unreachable dead code return 0 after return matrix in utils/loadData.py loadMatrix() method.

  • Fix mutable default argument apply_function_kwargs={}apply_function_kwargs=None with guard in utils/loadData.py getDataPerSubject() method.

  • Fix == Noneis None in utils/pypetUtils.py (PEP 8).

Test plan

  • No behavioral changes — bare except replacement preserves all Exception-derived catches
  • logging.warning() is the non-deprecated equivalent of logging.warn()
  • Dead return 0 was never reachable
  • Mutable default fix: None guard produces identical empty dict behavior

…and mutable default

- Replace bare `except:` with `except Exception:` in
  `utils/functions.py` (fcd) and
  `optimize/evolution/evolutionaryUtils.py` (saveToPypet).
  Bare except catches KeyboardInterrupt and SystemExit.

- Replace all `logging.warn()` with `logging.warning()` in
  `models/model.py` and `evolutionaryUtils.py`. `logging.warn()`
  has been deprecated since Python 3.3.

- Remove unreachable `return 0` dead code in
  `utils/loadData.py` loadMatrix method.

- Fix mutable default argument `apply_function_kwargs={}` →
  `apply_function_kwargs=None` in `utils/loadData.py`
  getDataPerSubject method.

- Fix `== None` → `is None` in `utils/pypetUtils.py` (PEP 8).
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.

1 participant