Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[TYP/MNT] Remove unused imports from stub files#25787

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 1 commit intomatplotlib:mainfromksunden:pycln
May 16, 2023

Conversation

ksunden
Copy link
Member

@ksundenksunden commentedApr 28, 2023
edited
Loading

PR Summary

mostly performed by runningpycln, but then manually audited

After it was brought up in#25728 (comment), I did a bit of a review, and consulted the python/typeshed repo for guidance on best practices for type stub files.
That repo has a precommit hook to runpycln -a on all files, which removes any imports that are implementation details that are not used in the public interface of the module.

Since that is the prevailing best practice of the relative authority on the matter, I decided to runpycln over our code.

The following additional changes were made after auditing the results:

  • The<...>_COLORS dictionaries are explicitly exported in the colors module
    • that they are imported is an implementation detail, but it is public within this module, as far as I can tell
  • TextPath is exported from thetext module.
    • despite existing in thetextpath module which is at least arguably public (at least by way of not having a prepended_)
    • TextPath is documented intext and thetextpath module is undocumented
  • A few others I questioned, but decided were not intended to be public api:
    • Helper functions in font_manager
    • legend_handler in thelegend module (legend_handler is its own public module, should be imported directly)
    • Helper functions forlayout_manager (even the ones that are documented contain a warning that they are considered private)
  • mathtext reexports values from_mathtext
  • A fewimport foo as foo areremoved as those are holdout from generating the stub files and are not intended to be exported
  • All changes to.py files were excluded, though perhaps someshould be removed
    • Files that would have changes:
      • galleries/examples/statistics/time_series_histogram.py
      • galleries/examples/ticks/date_formatters_locators.py
      • lib/matplotlib/init.py
      • lib/matplotlib/axes/_axes.py
      • lib/matplotlib/backends/backend_template.py
      • lib/matplotlib/backends/qt_compat.py
      • lib/matplotlib/pylab.py
      • lib/matplotlib/pyplot.py
      • lib/matplotlib/tests/test_determinism.py
    • many of these are actually intended to be exported, cause side effects, or are used viaeval (in galleries)
    • Unused imports aregenerally caught by flake8 ci, but have several instances of per-file-ignores for that error

pyclncould be added as a pre-commit hook here if we were interested, but would need to be properly configured, and current personal leaning is that it is not a big enough boon to do so, though checking when the topic comes up like it did here may be warranted.

PR Checklist

Linked Issue

  • [N/A] Added "closes #0000" in the PR description to link it to the original issue.

Documentation and Tests

  • [N/A] Has pytest style unit tests (andpytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • [N/A] API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • [N/A] Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@ksundenksunden changed the titleRemove unused imports from stub files[TYP/MNT] Remove unused imports from stub filesApr 28, 2023
@oscargus
Copy link
Member

Should we run isort on these as well?

@ksunden
Copy link
MemberAuthor

We could do so, though may wish to add config to e.g. group thempl.typing,typing (stdlib), andnumpy.typing imports together (potentially withcollections.abc as well, as that is also rather related)

Not opposed, but also don't really see it as a huge gain.

from matplotlib import cbook, ft2font
from matplotlib._fontconfig_pattern import (
generate_fontconfig_pattern,
parse_fontconfig_pattern,
Copy link
Member

Choose a reason for hiding this comment

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

Weirdly, this one is public enough to appear in API change notes, but not public enough to be in API documentation.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, I was debating on this one, current leaning is to leave it out of stubs until and unless someone complains, which I kind of doubt will happen.

mostly performed by running pycln, but then manually audited
@ksunden
Copy link
MemberAuthor

Gentle ping on this one

@tacaswelltacaswell merged commit9b13a56 intomatplotlib:mainMay 16, 2023
@ksundenksunden deleted the pycln branchMay 16, 2023 21:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

4 participants
@ksunden@oscargus@QuLogic@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp