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

Appearance settings

[TYP] Add tool for running stubtest #26928

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 5 commits into from
Oct 3, 2023
Merged

Conversation

ksunden
Copy link
Member

@ksunden ksunden commented Sep 26, 2023

PR summary

Walks the ast to find delete_parameter calls and automatically ignores them as their signature is modified at runtime

Could potentially be further modified to respect the alias behavior, which is the majority of the current allowlist (Added this feature)

Makes running stubtest easier as now it is just 'python tools/stubtest.py', rather than a long incantation with multiple arguments

This was discussed in part in #26894

PR checklist

Walks the ast to find delete_parameter calls and automatically ignores them as their signature is modified at runtime

Could potentially be further modified to respect the alias behavior, which is the majority of the current allowlist

Makes running stubtest easier as now it is just 'python tools/stubtest.py', rather than a long incantation with multiple arguments
@ksunden ksunden changed the title Add tool for running stubtest [TYP] Add tool for running stubtest Sep 26, 2023
@ksunden ksunden added this to the v3.9.0 milestone Sep 26, 2023
@QuLogic
Copy link
Member

QuLogic commented Sep 27, 2023

I'm curious whether this works when matplotlib is installed normally (non-editable), as that is something that I needed to do on the Meson branch.

@ksunden
Copy link
Member Author

ksunden commented Sep 27, 2023

Yes, it does appear to work on installed mpl

@story645
Copy link
Member

dunno if it's tangential to this, but would the preference be to use this to make a pre-commit hook or to use mypy-mirror? been looking at https://jaredkhan.com/blog/mypy-pre-commit

@ksunden
Copy link
Member Author

ksunden commented Sep 28, 2023

Stubtest takes longer than I'm really willing to put in a pre-commit hook (it runs mypy first and then does its checks which involve importing)

On my machine this takes over a minute in total:

  • ~3 seconds for the newly added ast parsing/generating of ignores in this script
  • ~15 seconds for mypy to run (judging based on running it independently)
  • ~50 seconds for stubtest itself to run

I could maybe justify normal mypy as a pre-commit (though running all of our precommit hooks (precommit run --all) currently takes less than 5 seconds (and the largest chunk is flake8, which I'm interested in replacing with faster ruff), so even 15 for mypy is pushing it a bit further, though pre-commit may run in more parallel)

Stubtest (well, at least this script as written) does not have as good of ways to only run on certain files. (you also specify by the import path because it is checking runtime behavior, so at least some manipulation would have to be done to the filepaths, though possible).

All of these numbers are on my (pretty beefy) desktop machine, and would hesitate to do something that makes it worse.

In all, not totally opposed to mypy, especially since I think it scopes to the edited files, so the worst case of 15 seconds is not likely to happen. but stubtest is probably good where it is at CI level and a tool that you can run locally if you either expect it to possibly fail or are diagnosing a failure from CI.

@story645
Copy link
Member

story645 commented Sep 28, 2023

so the worst case of 15 seconds is not likely to happen.

Even if it does, it's faster for me to fix locally then running through push/ci cycles

@ksunden
Copy link
Member Author

ksunden commented Sep 28, 2023

True, but whether it is worth it is dependent on not only the speedup of the failing path, but also the slowing down of the passing path and the proportion of changes which go down each path.

I am probably a bit of an outlier in that my changes are very bimodal with really small changes (where an extra 15 seconds is frustrating) and really large changes (where I'm running these tools locally myself multiple times before I get to committing even), so perhaps not the best one to make that judgement.

Again, I think I'd support adding mypy, but not stubtest, as a happy medium (especially if it scopes to edited files by default).

self.visit(child)


with tempfile.NamedTemporaryFile("wt", delete=False) as f:
Copy link
Member

Choose a reason for hiding this comment

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

Ensure this cleans up like the context manager:

Suggested change
with tempfile.NamedTemporaryFile("wt", delete=False) as f:
# Use delete_on_close when Python 3.12 is minimum.
f = tempfile.NamedTemporaryFile("wt", delete=False)
try:

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively you can just use a TemporaryDirectory instead and create a file with whatever name you want in that directory, to get both proper autodeletion without problems with close()ing the file. We use that pattern quite a few times in the library itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

tools/stubtest.py Show resolved Hide resolved
tools/stubtest.py Outdated Show resolved Hide resolved
@QuLogic QuLogic merged commit ef3bf5c into matplotlib:main Oct 3, 2023
Comment on lines +79 to +82
try:
os.unlink(f.name)
except OSError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Oops, I just realized this is still here; it can probably be deleted now that you're using TemporaryDirectory?

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

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.