Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit40369b5
committed
Automagically set the stacklevel on warnings.
There are many places in Matplotlib where it is impossible to set astatic stacklevel on warnings that works in all cases, because a samefunction may either be called directly or via some wrapper (e.g.pyplot).Instead, compute the stacklevel by walking the stack. Given thatwarnings refer to conditions that should, well, be avoided, I believewe don't need to worry too much about the runtime cost.As an example, use this mechanism for the "ambiguous second argument toplot" warning. Now both```plt.gca().plot("x", "y", data={"x": 1, "y": 2})```and```plt.plot("x", "y", data={"x": 1, "y": 2})```emit a warning that refers to the relevant line in the user source,whereas previously the second snippet would refer to the pyplot wrapper,which is irrelevant to the user.Note that this only works from source, not from IPython, as the latteruses `exec` and AFAICT there is no value of stacklevel that correctlyrefers to the string being exec'd.Of course, the idea would be to ultimately use this throughout thecodebase.1 parent1e6790f commit40369b5
2 files changed
+17
-4
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
64 | 64 |
| |
65 | 65 |
| |
66 | 66 |
| |
67 |
| - | |
| 67 | + | |
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
71 |
| - | |
| 71 | + | |
72 | 72 |
| |
73 | 73 |
| |
74 | 74 |
| |
|
Lines changed: 15 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
17 |
| - | |
| 17 | + | |
18 | 18 |
| |
19 | 19 |
| |
20 | 20 |
| |
| |||
1254 | 1254 |
| |
1255 | 1255 |
| |
1256 | 1256 |
| |
1257 |
| - | |
| 1257 | + | |
1258 | 1258 |
| |
1259 | 1259 |
| |
1260 | 1260 |
| |
| |||
2032 | 2032 |
| |
2033 | 2033 |
| |
2034 | 2034 |
| |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + |
0 commit comments
Comments
(0)