Skip to content

MAINT: Convert remaining percent-format strings to f-strings - #13974

Merged
larsoner merged 2 commits into
mne-tools:mainfrom
theosorus:convert-remaining-percent-fstrings
Jun 23, 2026
Merged

larsoner merged 2 commits into
mne-tools:mainfrom
theosorus:convert-remaining-percent-fstrings

Conversation

@theosorus

@theosorus theosorus commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Closes #12360

converts the percent-format strings that ruff's UP031 rule does not detect.

What does this implement/fix?

Converts the remaining operator-style "..." % (...) string formatting to f-strings in
source_estimate.py, dipole.py, _ola.py, mxne_optim.py and _source_space.py.
Output is unchanged: format specs like %6.1f become {...:6.1f}. Also cleans up one
mixed f-string + % formatting in _ola.py. The tabular %-format specs in chpi.py
(printf-style over numeric arrays) are intentionally kept.

Additional information

AI assistance: I used an AI assistant to help locate the remaining percent-format strings
and draft the conversions; I reviewed and verified each change myself.

Convert the operator-style ``"..." % (...)`` string formatting that ruff's
UP031 rule does not detect into f-strings (in source_estimate, dipole,
_ola, mxne_optim and _source_space). Output is unchanged; format specs
such as ``%6.1f`` are preserved as ``{...:6.1f}``. Part of mne-tools#12360.
@welcome

welcome Bot commented Jun 22, 2026

Copy link
Copy Markdown

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴

@larsoner

Copy link
Copy Markdown
Member

I think when looking at #13530 (comment) we decided that best practice was to get rid of % in logger calls rather than using f-strings in those (but use f-strings in warn calls and in raising errors). That being said I'm okay with using f-strings everywhere instead. @drammock do you have a strong preference here?

@drammock

Copy link
Copy Markdown
Member

I think when looking at #13530 (comment) we decided that best practice was to get rid of % in logger calls rather than using f-strings in those (but use f-strings in warn calls and in raising errors).

My read of that thread is that warn() gets f-strings, but logger.info(), logger.debug(), and raise all get/keep % style string formatting. But TBH the performance hit is likely to be quite small, so I'm OK with just doing f-strings everywhere even if it's not "best practice". We can always change our mind later (or do it selectively) if a performance problem emerges.

@theosorus

Copy link
Copy Markdown
Contributor Author

Thanks both for the feedback! Happy to go with f-strings here, Let me know if you'd rather I switch the logger calls to lazy %-args instead I can update quickly

@larsoner
larsoner merged commit 566bbe8 into mne-tools:main Jun 23, 2026
28 checks passed
@welcome

welcome Bot commented Jun 23, 2026

Copy link
Copy Markdown

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@larsoner

Copy link
Copy Markdown
Member

Thanks @theosorus !

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.

Replace percent format with format specifiers (f-strings)

3 participants