Skip to content
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

Improve stubgen tests #16760

Merged

Conversation

bluenote10
Copy link
Contributor

@bluenote10 bluenote10 commented Jan 7, 2024

Improve test cases around #16486

This PR does not change any actual mypy behavior, only hardens the stubgen tests. The specific changes are:

  • dedicated test cases: The existing pybind11 test cases originate from a pybind11 demo. They cover a specific topic involving geometry types and semi-implemented logic related to it. This somehow distracts from the aspects we are trying to test here from the mypy stubgen perspective, because it hides the actual intent of the bindings. I've simply started adding new test cases that clearly express via their name what the test case is addressing. I've kept the original demo stuff for now, so that the new cases are just an addition (overhead is negligible).
  • running mypy on the generated stubs: In general it is crucial that the output produced by the stubgen can actually be type checked by mypy (this was the regression in Retain None (unreachable) when typemap is None with type(x) is Foo check #18486). This wasn't covered by the CI check so far. I've added check now, which would have avoided the regression. My goal for follow up PRs would be that we can use mypy --disallow-untyped-defs or even mypy --strict on the output.
  • minor directory restructuring: So far the expected stub outputs were stored in folder names stubgen and stubgen-include-docs. This was a bit confusing, because the folder stubgen suggested it contains the stubgen (implementation). I went for expected_stubs_no_docs and expected_stubs_with_docs to make the role of the two folders more explicit.
  • minor script bugfix: Fix a bug in test-stubgen.sh: The pre-delete functionality was broken, because the * was quoted and therefore did not match.

@bluenote10 bluenote10 force-pushed the feature/improve_stubgen_test_cases branch from 494a072 to 1e56aa4 Compare January 7, 2024 17:24
@bluenote10 bluenote10 force-pushed the feature/improve_stubgen_test_cases branch from 1e56aa4 to ff885c3 Compare January 7, 2024 17:26
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

I'm happy to merge this but would like @chadrik to also take a look (if you have time).

@chadrik
Copy link
Contributor

chadrik commented Jan 13, 2024

This looks fantastic. My only nit is that it would be nice to change the name of the folder from pybind11_mypy_demo to pybind11_fixtures, since it's no longer a demo, it's an extension of the test suite.

That said, I have no problem merging as-is.

@bluenote10
Copy link
Contributor Author

My only nit is that it would be nice to change the name of the folder from pybind11_mypy_demo to pybind11_fixtures, since it's no longer a demo, it's an extension of the test suite.

Absolutely, very good idea! I've just pushed that as well.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit a8741d8 into python:master Jan 13, 2024
19 checks passed
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.

3 participants