Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove many unused variables. #13932

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 1 commit into from
Apr 23, 2019
Merged

Remove many unused variables. #13932

merged 1 commit into from
Apr 23, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 11, 2019

They can be detected by removing the exclusion of F841 in .flake8.

AFM parsing was made slightly stricter as a consequence (see changelog).

Some other unused variables have been left in, either for symmetry in
the code or because their lack of use may possibly indicate a bug that
needs to be investigated.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer force-pushed the unused branch 2 times, most recently from 041ddf1 to 088dbe1 Compare April 11, 2019 18:11
@dstansby
Copy link
Member

I'd be nervous about removing any of these that don't have coverage in the test suite, lets see what happens though.

@@ -0,0 +1,5 @@
Stricter parsing of the Composites section of AFM files
Copy link
Member

Choose a reason for hiding this comment

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

The PR title and commit message suggest that it does not have any effect on running code. However, here you state an API change. I'd feel much safer if this was a separate PR, not least because this PR is large.

@anntzer
Copy link
Contributor Author

anntzer commented Apr 13, 2019

Reverted the changes to afm.py.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

IMHO this PR is too big, and thus makes reviewing difficult. I just got 1/3 though and then had to stop for doing other things. My motivation to take it up again is quite low.

For reviewing it's better to have multiple smaller PRs. You could just do it for a limited number of files in the first step.


# This only affects axes in first column and second row as share_all =
# False.
ax.imshow(Z, extent=extent, interpolation="nearest")
Copy link
Member

Choose a reason for hiding this comment

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

I loosely recall that there was a discussion if examples should have return values even though they are not used.

Advantage: The user sees that this returns an object that can be used further.
Disadvantage: In practical use, you would only define the return value if you actually need it. So the example does not represent how you would use Matplotlib in real life. And it's more cluttered than need be.

Personally, I'm fine with removing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope no one is reading axes_grid demos to learn about basic mpl concepts such as artists being returned by most calls :)

@@ -455,7 +455,7 @@ def _fnt_def_real(self, k, c, s, d, a, l):

@_dispatch(247, state=_dvistate.pre, args=('u1', 'u4', 'u4', 'u4', 'u1'))
def _pre(self, i, num, den, mag, k):
comment = self.file.read(k)
self.file.read(k) # comment
Copy link
Member

Choose a reason for hiding this comment

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

This change removes semantics. Either use _comment = ... or make the comment message more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that variable is not used, this is just reading a comment and throwing it away. slightly edited the comment about the comment :)

@anntzer
Copy link
Contributor Author

anntzer commented Apr 14, 2019

Sounds fair re: PR size; split out changes to tests (which are actually the majority of changes) to #13957.

attrib = {}
# Must add "px" to workaround a Firefox bug
style['font-size'] = short_float_fmt(fontsize) + 'px'
style['font-family'] = str(fontfamily)
style['font-size'] = short_float_fmt(prop.get_size()) + 'px'
Copy link
Member

Choose a reason for hiding this comment

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

.get_size_in_points and .get_size are methods with identical bodies....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know... planning to deprecate get_size_in_points but there are bugger issues with fontproperties anyways.

@tacaswell tacaswell added this to the v3.2.0 milestone Apr 21, 2019
@tacaswell
Copy link
Member

I think this has gotten much smaller from when @timhoffm first reviewed it.

@@ -582,7 +582,7 @@ def configure_subplots(self, button):
toolfig = Figure(figsize=(6, 3))
canvas = self._get_canvas(toolfig)
toolfig.subplots_adjust(top=0.9)
tool = SubplotTool(self.canvas.figure, toolfig)
SubplotTool(self.canvas.figure, toolfig)
Copy link
Member

Choose a reason for hiding this comment

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

The question this raises is, what keeps the SubplotTool instance alive when no reference to it is saved--not even until the end of this method? Presumably something external does get a reference, and I just don't see it. Otherwise, even without this change, the reference would last only until the end of the method.

Copy link
Member

Choose a reason for hiding this comment

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

I also don't see who is holding the reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually a bit curious because the Tool object needs to stay alive even after the function has exited (so that the callbacks are not garbage-collected), but it's not clear to me what makes this possible.
In any case I checked, we do need to maintain a referrence to tool in case e.g. a gc collect()ion occurs in the body of the function, so I reverted this change and left a comment.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

It would be good if we can find out who's holing the SubplotTool reference. Otherwise, this looks ok.

@anntzer anntzer force-pushed the unused branch 2 times, most recently from 2b3ce74 to abd9b67 Compare April 23, 2019 07:58
@@ -160,6 +160,7 @@ def prepare_configure_subplots(self):
toolfig = Figure(figsize=(6, 3))
canvas = FigureCanvasMac(toolfig)
toolfig.subplots_adjust(top=0.9)
# Need to keep a reference to the tool.
tool = SubplotTool(self.canvas.figure, toolfig)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tool = SubplotTool(self.canvas.figure, toolfig)
_tool = SubplotTool(self.canvas.figure, toolfig)

The underscore prefix is commonly used as "intentionally unused"; e.g. Pycharm does not mark the variable as unused anymore with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, done

They can be detected by removing the exclusion of F841 in .flake8.

Some other unused variables have been left in, either for symmetry in
the code or because their lack of use may possibly indicate a bug that
needs to be investigated.
@timhoffm timhoffm merged commit 3ba7b19 into matplotlib:master Apr 23, 2019
@anntzer anntzer deleted the unused branch April 23, 2019 13:40
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