Skip to content

Fix 23 mutable default arguments across 9 files#7

Open
stef41 wants to merge 4 commits intoatomgptlab:developfrom
stef41:fix-mutable-default-arguments
Open

Fix 23 mutable default arguments across 9 files#7
stef41 wants to merge 4 commits intoatomgptlab:developfrom
stef41:fix-mutable-default-arguments

Conversation

@stef41
Copy link
Copy Markdown

@stef41 stef41 commented Apr 17, 2026

Summary

23 function signatures across 9 files use mutable default arguments (=[], ={}), which is a well-known Python anti-pattern. Mutable defaults are evaluated once at function definition time and shared across all calls, so data from one invocation can silently persist into the next.

Changes

Replaced mutable defaults with None and added if param is None: param = ... initialization guards.

Affected files

File Fixes
alignn/ff/ff.py 7
alignn/graphs.py 6
alignn/pretrained.py 2
alignn/dataset.py 2
alignn/lmdb_dataset.py 2
alignn/ff/calculators.py 1
alignn/train.py 1
alignn/scripts/cubic_mat_relax.py 1
alignn/scripts/make_test_split_cross_pred.py 1

All modified files pass python -m py_compile.

Previously submitted as usnistgov/alignn#196, resubmitted here per @knc6's direction.

knc6 and others added 4 commits September 14, 2025 06:10
Replace mutable defaults (`=[]`, `={}`) with `None` sentinels and
add `if param is None: param = ...` guards in the function body.

Mutable defaults are evaluated once at function definition time and
shared across all calls, so data from one invocation can silently
persist into subsequent calls.
@knc6 knc6 changed the base branch from main to develop April 17, 2026 13:30
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