Skip to content

Warn about unused kwargs in contour methods#7728

Merged
tacaswell merged 3 commits into
matplotlib:masterfrom
dstansby:unused-kwarg-warnings
Aug 14, 2017
Merged

Warn about unused kwargs in contour methods#7728
tacaswell merged 3 commits into
matplotlib:masterfrom
dstansby:unused-kwarg-warnings

Conversation

@dstansby

@dstansby dstansby commented Jan 2, 2017

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Comment thread lib/matplotlib/contour.py
for key, value in kwargs.items():
s += '"' + str(key) + '"' + ', '
warnings.warn('The following kwargs were not used by contour: ' +
s)

Copy link
Copy Markdown
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

anntzer commented Apr 16, 2017

Copy link
Copy Markdown
Contributor

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

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

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).

Comment thread lib/matplotlib/contour.py
"""
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@tacaswell

Copy link
Copy Markdown
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

QuLogic commented Aug 11, 2017

Copy link
Copy Markdown
Member

Do we need the rename suggested here?

@dopplershift dopplershift left a comment

Copy link
Copy Markdown
Contributor

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

QuLogic commented Apr 22, 2020

Copy link
Copy Markdown
Member

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