-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Raise TypeError on unsupported kwargs of spy() #11367
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
Conversation
While you're at it: wouldn't it make sense to allow for the |
e6e8fae
to
0a1c674
Compare
Actually, the current hard-coded implementation of
The fix is to not handle
|
04a7b8d
to
393e6db
Compare
Why do we want to explicitly check for these kwargs? We silently ignore all other superfluous kwargs... |
No I guess the idea is to pass all arguments to the underlying I think one could as well pop them from the kwargs and issue a warning instead. |
I’d be fine w a warning. But I’m not aware that we blacklist unused kwargs unless they conflict with another kwarg so I’d argue that should be changed. |
Is this warn-on-unsupported **kwargs, but do not raise a TypeError, an agreed procedure? I have the feeling it's just something that nobody cared to check **kwargs so far. IMO passing an invalid **kwargs is a fundamental programming error that should be detected and the source code adapted. Warnings may be overlooked. I'd opt for TypeError If you pass an invalid kwarg to a function without **kwargs, this raises a TypeError. I think would be consistent to do the check so that **kwargs is not a wild-card, but just an abbreviation for for a defined set of parameter names. |
I think this also depens on what is valid according to the docs. |
393e6db
to
d884b2d
Compare
Changed to just show a warning. |
lib/matplotlib/axes/_axes.py
Outdated
if 'linestyle' in kwargs: | ||
kwargs.pop('linestyle') | ||
warnings.warn( | ||
'"interpolation" keyword argument will be ignored', |
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.
This should be "linestyle" instead of "interpolation"
d884b2d
to
736b1d2
Compare
@dstansby I've fixed your requested change. |
I agree that passing unused So for what it's worth, I'd strongly recommend raising TypeError instead of a warning as was done in #11137, #11145, #11146, and #11271; this is one of the principles for Matplotlib 3.0! |
@ImportanceOfBeingErnest @jklymak Is it ok if I switch back to error? |
Would it be better to do |
Since my opinion was asked here: Yes raising an error should be fine as well; as commented already, the docs should then explicitely list the forbidden arguments. A default linestyle argument does not make sense in my view. The reason is simply that you never want any linestyle for a |
Moved to 3.1. |
736b1d2
to
3abe033
Compare
I agree with @ImportanceOfBeingErnest that a linestyle does not make sense in this context. This is a special purpose function and connecting the individual markers would be misleading at best. Concerning warning vs. error: Will switch back to an error. |
3abe033
to
5a872b0
Compare
Agree with making conflicting kwargs an error as they are otherwise silently ignored. |
@jklymak you approved the previous iteration where it was just a warning, are you still ok with the current design? |
If there are conflicting arguments an error is fine. If there are unused arguments I’m still wary that this sets up the expectation that we will trap unused args elsewhere and we don’t. |
Well, trapping unused arguments throughout the library is a bit a work in progress, isn't it? |
I dunno, is that something we are trying to do? I'm not against it per-se if folks are willing to do it, it just seems like a heavy lift... |
In my opinion, we should catch unused arguments. People think they achieve some effect when using these arguments. And we silently ignore their intent. „You can pass xxx but it does nothing.“ is usually not a good API. Currently not doing this in all the places is no reason for not at least trying to move into the direction. After all, we currently have a mixed state. |
#7728 for similar "warn-on-unused-kwarg" work. |
thanks |
PR Summary
spy()
accepts and silently ignores the kwargs 'extent', 'interpolation' and 'linestyle'. This PR changes the behavior to throw aTypeError
instead.