-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MRG: Add a locking/unlocking context manager to Info for error checking. #9867
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
MRG: Add a locking/unlocking context manager to Info for error checking. #9867
Conversation
Can you give me an example of what you mean? |
|
I added a couple of error messages as examples. Now is a good time to settle on a common syntax.
Maybe replacing instance methods with a more explicit Note that I do not know what should be the error message for most of them. I do not know which function users are supposed to use, especially for all the MEG-related attributes. Some help on this part would be appreciated. I will start adding the unlocking context manager across MNE functions to get more and more CI tests working again. |
This comment has been minimized.
This comment has been minimized.
Figuring out which
There are some circumstances where it can help to set it, but they're pretty rare. I guess for now we say yes |
This comment has been minimized.
This comment has been minimized.
|
We have some magic to override deepcopy to speed it up, perhaps it's in there |
|
The copy was an easy one indeed.
|
😁😎 |
|
That was fast! I wasn't expecting to wake up this morning with CI all green and the diff down again, thanks! |
|
I broke the symmetry, soorry 😅
In another PR? |
|
One more bug somewhere, unrelated. I was playing around with the xdawn example and I got this: With: Problem is with |
|
To build upon this, I thought about defining an info and the montage from the epochs instead of resampling. But, it's a pain to match the element in For another PR as well, right? |
I consider this a bug with
In principle I think you should be able to use
Argh I had assumed that this would route through @agramfort I think this one is ready to go |
agramfort
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know a number of projects / code that use info to store temporary stuff that are moved around with the inst. With this PR it's not possible anymore without a warning and knowing about the private _unlock method. What you think of allowing a dedicated key eg "misc" "stuff" "tmp" that user would be free to use without having anything to justify?
I don't mind, but I'm not the one to convince #9867 (comment) 😉 With the code in the PR, you get a warning if you define a non-valid key, BUT you don't need to be in an unlocked state to do so. Thus, users don't have to know about the private locking/unlocking functions. |
|
I can live with 1) one cycle of deprecation warning saying it will be an error in the next release, and 2) add info["temp"] as an explicit temporary (won't survive round trip) option for people going forward. |
|
@larsoner For the deprecation warning, I don't know how you want to set it up. I'm guessing the decorator I added the |
|
Why is that? I think it's better if this variable remains flexible and if users can set it as they want.
+1
|
|
@hoechenberger feel free to take a look at |
|
Okay let's see how much stuff we break, thanks @mscheltienne ! |
Following the discussion on #9752 and the proposition in #9767 (comment), here is a possible implementation of @larsoner proposition.
I removed the try/else/finally block, as at least for now, it might be masking potential bugs.
I added the unlocking context manager under the
_unlockname; with the current state in a variable named_unlocked.I added a list of all the valid attributes in
Infoin the form of the dictionary_attributes. For each valid key, the value is either:Infoattributes without unlocking first towards the correct setter function.I added the corresponding
__setitem__method. I kept the possibility to set non-valid keys with a warning message.This is obviously not going to pass the CI tests, as the MNE function setting attributes now have to be changed to use the context manager. Is this proposition with a dictionary containing either the error message to raise or the checker function OK for everyone?
What are the attributes that can be set directly by the users and that need a quick checker function?
Correct? Any others?
For the checker function, is a check of the type as proposed good enough for now, with potential improvements later on?
e.g. for
badswe could check that the elements of the list are within the infoch_names.