Skip to content

MAINT: Check for shadowing and mutable defaults #12380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 23, 2024
Merged

Conversation

larsoner
Copy link
Member

Enable rules to avoid shadowing builtins (should help with stuff like #12352) and mutable defaults. Found a real bug that could be out there in user code (but hopefully rare!) due to mutable defaults along with added test. Added exceptions/noqa for things like format="nifti"-style kwargs where it doesn't seem like a deprecation cost would be worth the gain of avoiding the shadowing.

Pushing with ci skip, will merge main into this PR once #12377 lands. Can be reviewed in the meantime if someone wants, though.

@@ -1382,6 +1382,7 @@ def reset_warnings(gallery_conf, fname):
r"iteritems is deprecated.*Use \.items instead\.",
"is_categorical_dtype is deprecated.*",
"The default of observed=False.*",
"When grouping with a length-1 list-like.*",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drammock
Copy link
Member

thank you for tackling this. The shadowed imports have been bugging me lately and I was hoping to get around to it this week. 🙏🏻

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good, I didn't notice anything weird. Two thoughts:

  1. a utility function param = convert_none_default_to(param, mutable_default) might be nice (but seems low priority)
  2. is it worth it to someday change the param names in the public API that are shadowing built-ins? e.g. id, format

@larsoner
Copy link
Member Author

is it worth it to someday change the param names in the public API that are shadowing built-ins? e.g. id, format

I don't think so -- the code paths where we use those is small so low risk of doing something bad, we don't need for example id or format in them (and even if we did we could from builtins import ... under different names), and it will cause code churn for end users. So very small gain for some end user pain I think.

@larsoner larsoner removed the request for review from mscheltienne January 23, 2024 16:06
@larsoner larsoner enabled auto-merge (squash) January 23, 2024 16:06
@larsoner larsoner merged commit 71faac9 into mne-tools:main Jan 23, 2024
@larsoner larsoner deleted the ruff branch January 23, 2024 17:56
larsoner added a commit to larsoner/mne-python that referenced this pull request Jan 23, 2024
* upstream/main:
  MAINT: Check for shadowing and mutable defaults (mne-tools#12380)
  Bump actions/cache from 3 to 4 (mne-tools#12374)
  MAINT: Work around pytest issue (mne-tools#12377)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12378)
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
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