MNT: Set stacklevel manually for warnings.#3467
MNT: Set stacklevel manually for warnings.#3467hmaarrfk wants to merge 15 commits intoscikit-image:masterfrom
Conversation
Of course. I'll have a look once I have access to my notebook again. |
|
I’m not so sure if this te correct way to go about it. This is a pretty big change to many different files. I don’t think warnings are as rigorously tested as other aspects of the code. I think the previous fun tools.partial solution is leas intrusive and we can “discourage” the use of that convenience if we want to. |
6f5d1c3 to
10f8206
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f495f41 to
005a175
Compare
|
@stefanv I know this change is much more intrusive, but it allows the use of that scipy script you mentioned. I think it is a much better fix long term. Definitely in the right direction for usability. |
|
@scikit-image/core your input on how to deal with the code vendored from scipy would be helpful. I can rebase once #3458 gets in. |
fb601f2 to
02bf9cc
Compare
02bf9cc to
e0e04fc
Compare
soupault
left a comment
There was a problem hiding this comment.
2 comments, otherwise 👍. Thanks Mark!
| if not has_qt: | ||
| warn('Viewer requires Qt') | ||
| from warnings import warn | ||
| warn('Viewer requires Qt', stacklevel=2) |
There was a problem hiding this comment.
Yea, could be 1. I tested this quite a bit, doesn't actually matter on what you select.
| "data's number of dimensions.") | ||
|
|
||
| im2pi = 1j * 2 * np.pi | ||
| # For the 2D case, it is more efficient to use the well-optimized |
There was a problem hiding this comment.
Is this change intended to be here?
There was a problem hiding this comment.
Yeah. I'm really not sure. I didn't have time to figure out why the rebase went astray
There was a problem hiding this comment.
Thahnks you two. I think what happened was that that function was simplified. I was more careful with my rebase now and I think all is well.
576b77f to
ed55686
Compare
|
@hmaarrfk thanks for the update! You've missed a couple of the old-style imports it seems: https://dev.azure.com/scikit-image/scikit-image/_build/results?buildId=231 |
b95581b to
11b236c
Compare
|
I guess a few more warns where added. I hope I got the stack levels right... |
11b236c to
8c2a1bd
Compare
|
@scikit-image/core I just rebased this for 0.16. If anybody wanted to look at this, I think it will help users follow our changes in their code and help them transition as we add/improve the library. thanks |
|
|
||
|
|
||
| """ | ||
| Copyright (c) 2001, 2002 Enthought, Inc. |
There was a problem hiding this comment.
We distribute all license text in the main LICENSE.txt now.
There was a problem hiding this comment.
Do you want to remove it from this file as well? I find it useful to keep the license in the file for these single "borrowed" files from libraries.
There was a problem hiding this comment.
Either way is fine, as long as it is listed in the main license file as well.
|
Would it make sense to have a default stacklevel of 2, rather than specifying it almost everywhere. Also, can we provide some guidance to developers on how to determine the correct stacklevel? |
|
I think i had a PR where the default stack level was simply set to 2, unfortunately, when refactoring code, it becomes common to put warnings in a common function where the stack level should be 3. In that case, incrementing the stacklevel often gets forgotten. Warnings, as shown by many of Issues recently, warnings are quite intrusive (though not as intrusive as your code breaking) and thus I think they warrant some thought at the time the PR is made. I think the few times where stack level is set to 3 makes it quite important to ask the contributor to think about who should receive the warning. Generally, you should set them so that users get pointed to their line of code, where they can take an action to remedy the situation. |
|
I think i had a PR where the default stack level was simply set to 2, unfortunately, when refactoring code, it becomes common to put warnings in a common function where the stack level should be 3. Warnings, as shown by many of Issues recently, are quite intrusive (though not as intrusive as your code breaking) and thus I think they warrant some thought at the time the PR is made. Finally, that script you found @stefanv is pretty godly, it parses the python AST to find where Generally, you should set them so that users get pointed to their line of code, where the user can take an action to remedy the situation. |
|
I would very much appreciate a paragraph or two about how to correctly use stacklevels in the developer guide. I'm still fuzzy about how to correctly think about them. Yes, I remember your old PR and people complaining that maybe it wasn't the right thing always. 😂 can't please everyone! fwiw I think I like this better because contributors are more likely to be familiar with warnings.warn than skimage.util.warn. |
|
@scikit-image/core what is the best way to get this through? should we just That said, a recent PR that added many deprecation warnings basically points users to some obscure location in internal scikit-image functions with no recourse on where in their code they need to make the modifications. I really think this PR adds alot of usability to the deprecation policy. |
ab80043 to
70ce8c4
Compare
|
@hmaarrfk I still think I like this approach, sorry that it's been hard to get through. When I need to warn I typically |
… unset stacklevels.
70ce8c4 to
adc31e9
Compare
|
The only thing left in this PR is the test that goes through the AST and checks all warnings calls. Clearly There isn't a concensus on using the internal warn function or the the standard python one. I opened PRs where the only thing I did was correct the places in here where the warning stack level wasn't set up correctly. I'm going to close this PR and others are free to reopen if consensus is reached. |
Add a test to catch future unset stacklevels.
The test added here needs this PR to pass: #3459
@lagru your help on this would be appreciated.
Either this, or #3438 should be pulled in.
Depends on what style you like. See discussion on #3438 for more details.
Checklist
[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
[For detailed information on these and other aspects see scikit-image contribution guidelines]
References
[If this is a bug-fix or enhancement, it closes issue # ]
[If this is a new feature, it implements the following paper: ]
For reviewers
(Don't remove the checklist below.)
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x