Skip to content

Warn about unused kwargs in contour methods #7728

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

Merged
merged 3 commits into from
Aug 14, 2017

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Jan 2, 2017

I got interested in #1963 (and I think there's another similar bug somewhere out there...), so thought I'd have a go.

The general method behind what I've done is

  • Every time a kwarg is retrieved, make sure it is poped
  • This should mean that by the end of the __init__ block, all the kwargs that are used have gone, and any unused kwargs are left behind

I think it should be in theory fairly easy (but very tedious) to roll this out to all methods.

This is probably fairly experimental, so happy for it to be discussed/reviewed and not necessarily merged!

@tacaswell
Copy link
Member

I am concerned about spending too much time on this before we drop python2. Once we are 3 only we can start to use keyword-only arguments so anything the function uses goes in the signature (no popping!) and kwargs are only used when things need to fall through to the next layer down.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 2, 2017
for key, value in kwargs.items():
s += '"' + str(key) + '"' + ', '
warnings.warn('The following kwargs were not used by contour: ' +
s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just be ", ".join(map(repr, kwargs)).

@anntzer
Copy link
Contributor

anntzer commented Apr 16, 2017

Still, it looks like a reasonable improvement. Minor nitpick, but otherwise looks good.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always roll this back when we move to Py3 only (hopefully soon).

@@ -1532,7 +1542,7 @@ def _check_xyz(self, args, kwargs):
Exception class (here and elsewhere).
"""
x, y = args[:2]
self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
kwargs = self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it's passed as a mutable value, so you don't technically need to return it. It should be the same object coming out as going in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming the method to _pop_and_process_unit_info (_pop_and_apply_unit_info to save two characters) for clarity -- sneakily modifying a mutable argument usually leads to a lot of head-scratching.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am 👎 on renaming it because it has had the current name for a long time and has always probably had this pop behavior.

In any case that change is outside of the scope if this PR.

@tacaswell tacaswell closed this Aug 10, 2017
@tacaswell tacaswell reopened this Aug 10, 2017
@tacaswell
Copy link
Member

'powercycled to re-run against current master + restart CI.

@tacaswell
Copy link
Member

circle CI is failing because it needs to be re-based on current master to pick up the proper config.

@dstansby dstansby force-pushed the unused-kwarg-warnings branch from 30ad984 to 4481344 Compare August 10, 2017 10:38
@QuLogic
Copy link
Member

QuLogic commented Aug 11, 2017

Do we need the rename suggested here?

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improves the status quo, so let's not hold it up for theoretically better naming of old functions.

@tacaswell tacaswell merged commit a455f1c into matplotlib:master Aug 14, 2017
@dstansby dstansby deleted the unused-kwarg-warnings branch August 23, 2017 13:16
@QuLogic
Copy link
Member

QuLogic commented Apr 22, 2020

Note that this warning is somewhat the opposite of what's requested in #2369, i.e., pass extra keyword arguments to the artist properties of the generated contour object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants