Skip to content
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

Fix string format "blabla" "bla" #1243

Merged
merged 5 commits into from
Apr 2, 2024
Merged

Conversation

mscheltienne
Copy link
Member

@mscheltienne mscheltienne commented Apr 2, 2024

PR Description

I propose to change the stacklevel of a couple of warnings I encountered, because

<ipython-input-34-b78341704568>:1: RuntimeWarning: Converting data files to BrainVision format

is really not that informative and I would appreciate to quickly jump to the function issuing the warning.

While I was on it, I fixed probably all the occurrences of "blabla" "bla" strings.
I don't believe this minor maintenance PR needs a changelog entry.

Merge checklist

Maintainer, please confirm the following before merging.
If applicable:

  • All comments are resolved
  • This is not your own PR
  • All CIs are happy
  • PR title starts with [MRG]
  • whats_new.rst is updated
  • New contributors have been added to CITATION.cff
  • PR description includes phrase "closes <#issue-number>"

@larsoner
Copy link
Member

larsoner commented Apr 2, 2024

To me if you did mne_bids.something(...) in the interpreter the correct line to get in the warning is the current input one. Typically it's most informative and standard to emit the caller line rather than the something

@mscheltienne mscheltienne changed the title Warn at stacklevel=2 for conversion to BrainVision format Fix string format "blabla" "bla" Apr 2, 2024
@mscheltienne
Copy link
Member Author

mscheltienne commented Apr 2, 2024

OK, I did not notice this was using mne.utils.warn and not directly warnings.warn, so indeed the caller line is returned which can be informative.

In an ideal world, we would get both the caller line and the line where the warning was emitted (stacklevel=1, to quickly jump to the warning line and figure out why it was emitted in the first place). I use this second option very often.

Anyway, for now I removed that erroneous stacklevel=2 part.

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 97.60%. Comparing base (87eea28) to head (81ae67d).
Report is 18 commits behind head on main.

Files Patch % Lines
mne_bids/commands/mne_bids_crosstalk_to_bids.py 50.00% 1 Missing ⚠️
mne_bids/commands/mne_bids_mark_channels.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1243      +/-   ##
==========================================
- Coverage   97.61%   97.60%   -0.02%     
==========================================
  Files          40       40              
  Lines        8685     8682       -3     
==========================================
- Hits         8478     8474       -4     
- Misses        207      208       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@larsoner
Copy link
Member

larsoner commented Apr 2, 2024

In an ideal world, we would get both the caller line and the line where the warning was emitted (stacklevel=1, to quickly jump to the warning line and figure out why it was emitted in the first place). I use this second option very often.

In theory it should be a few lines to add an add_caller=False to mne.utils.warn that uses the adjacent stack frame calling function somehow like:

<ipython-input-blah>:1: RuntimeWarning: In call to mne_bids.something: Converting data files to BrainVision format

then mne-bids could make use of it.

Maybe we'd even want add_caller=True by default...?

@mscheltienne
Copy link
Member Author

@larsoner That's a nice idea, and would give the caller line, but only as text right? VSCode terminal does some nice magic to enable a Ctrl + click on the emitted warning to jump to the line.

Screenshot from 2024-04-02 15-41-23

With that proposition, the caller line would not benefit from the same 'link' to jump to the definition; and thus without this I don't see the added benefit compared to quickly searching for the error string within the codebase.

Anyway, I will give it a try and see how it renders ;)

@mscheltienne
Copy link
Member Author

Let's keep this PR as a simple string format fix then, mark for merge if happy :)

Copy link
Member

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

Thanks @mscheltienne!

@sappelhoff sappelhoff merged commit 598ff7f into mne-tools:main Apr 2, 2024
17 of 19 checks passed
@mscheltienne mscheltienne deleted the fix branch April 2, 2024 15:59
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.

None yet

4 participants