Set appropriate stacklevel for userwarnings#2405
Conversation
|
Truthfully, I patched up until i found the warning I was getting, and stopped. This could be more extensive, but I probably don't have the time to go through this all. |
|
Not going to lie (and I say this because you've been involved with vispy for so long), this is ugly. That said, I understand the need for it. What are the difference cases for the different stack levels that If we assume users aren't using gloo-level classes directly then would @brisvag thoughts? |
| interpolation=None, wrapping=None, shape=None, | ||
| internalformat=None, resizeable=None): | ||
| internalformat=None, resizeable=None, | ||
| _stacklevel_increment=0): |
There was a problem hiding this comment.
I think you can remove them from here, but the more you try to delegate, the more you will find yourself needing these.
I know it is ugly, but the thing you really want to avoid is somebody filtering away all the warnings, because you point them inside a helper function.
Filter all is really easy to write.....
|
Yeah, I'm not a huge fan either... Is it problematic to just always point the max amount of levels up in the "public" api? |
You can do that if you can figure out where the public API boundary lives. |
|
Is this idea too insane? It looks for the nearest stack frame that points to a file outside the vispy search path. It takes ~0.3 ms for the first execution and is ~10x faster for subsequent calls. |
|
Besides whether it is valid or not, would it make sense to remove the "not" and return the level inside the if statement? |
|
You mean walk the stack in the other direction? |
|
No. I mean I don't think "break" is necessary. You could just put the return there instead of breaking. I'm not sure what I was thinking when I said to remove "not", ignore that. |
|
Ohh, I see. Yes. You're right. The only difference is if it never finds a stack frame with a file outside the vispy path, it would return |
|
Yeah, leave it as is. |
I typically try to set the stacklevel to point to the correct location where the user can fix the warning in their code.
Previously, the stack level would point the user to some deep deep internal method for vispy.
The
_stacklevel_incrementis designed to be an internal (vispy-only) parameter that allows passing the warning upward to the user's originating call.