8000 [stubgenc] fixes and typos by sizmailov · Pull Request #9877 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[stubgenc] fixes and typos #9877

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 6 commits into from
Jan 20, 2021

Conversation

sizmailov
Copy link
Contributor

Description

This PR consist of series of minor changes to stubgenc, including typos in comment and (unfortunately) in code, one bug fix in docstring parsing and minor tweak to generate a better stubs for pybind11 modules. Hopefully commit messages are explanatory enough.

This might be vague PR of small but rather disconnected changes, let me know if this must be split in smaller once.

Test Plan

So far this PR does not include test, therefore is marked as draft.
Locally I've additionally tested stubs generation for a small pybind11-based project (https://github.com/sizmailov/pybind11-project-example). As far as I can tell currently there is no tests in CI against actual pybind module. Not sure if it's desirable to have one.

Please let me know if tests for this changes are required.

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from 45b57d2 to 535fc74 Compare January 5, 2021 01:55
@JukkaL
Copy link
Collaborator
JukkaL commented Jan 6, 2021

Thanks for the PR and your attention to detail!

It's okay to have all of these changes in a single PR, since they are all pretty simple.

Having tests against a pybind module could be nice, assuming no extra big dependencies are needed and these tests aren't complex or slow. I'd prefer if the dependency could be included in test-requirements.txt, for consistency.

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from 535fc74 to ebd8d01 Compare January 6, 2021 23:33
Copy link
Contributor Author
@sizmailov sizmailov left a comment

Choose a reason for hiding this comment

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

I've added basic check for generated stubs for real pybind11 project.

The check is full-text match. This is probably imperfect but I don't immediately see what alternative we have.

The C++ code is included as external dependency to a specific branch to my own repo. This is obviously cannot be merged as is. Please tell how to deal with it. Setting up "official" repo seems to be overkill, so I'm inclined to full-text include of linked repo to mypy. Again, I don't have strong opinion here.

I've placed expected stubs under test-data/stubgen/. Seems fine to me, but could be wrong.

@JukkaL
Copy link
Collaborator
JukkaL commented Jan 7, 2021

Hmm the test set up feels rather complex and I can see it becoming painful to maintain. Also it would be nice if we can avoid numpy as a dependency, since it's fairly big and might slow down CI.

Here are some alternatives (which aren't perfect though). Let me know what you think about them.

  1. Low-tech, manual tests: Add a script to misc/stubgenc-extra-tests/, for example, that installs the deps (here we can depend on numpy etc.), builds and installs the wheel and runs the tests. We wouldn't have this running in CI, but reviewers can ask contributors to run this manually if they modify stubgenc.
  2. Upload binary wheels for an example package that uses pybind11 to PyPI (for at least one platform) and add a regular PyPI dependency to test-requirements.txt (possibly conditional). The test can now be run as part of the normal test suite (skipped on non-supported platforms), and no build step should be needed.
  3. Don't bother with having tests in the mypy repository.
  4. Only write unit tests that don't need pybind11.

For option 2, you can pin a well-known, pre-existing package that uses pybind11 (so that the dep is already available and can be expected to stay relatively up-to-date). You could also set up a new PyPI package dedicated to this test only. Some mypy core devs would probably need write access to upload new versions of the package, and the build and upload scripts could perhaps live in the mypy repository.

(I'm not very familiar with pybind11 so it's possible that my suggestions don't make much sense.)

@sizmailov
Copy link
Contributor Author

I think stubgenc test shouldn't be run on CI unless related code is affected. Therefore it would be ok to include numpy tests to this relatively rare CI job.

I would go with option 2 since some tests are better than none, and automatic test are better than manual.

I've contacted pybind11 maintainers in gitter chat and I think there is a good chance to have a maintainable repo dedicated to test stubgen's ability to precisely render pybind11 modules. The only remaining question is where this project should be hosted (e.g. under github.com/python/ or github.com/pybind/).

This might take some time to compose a concise "pybind11 mypy demo" repo along with PyPI package, but it's surely worth it.

(My test repo with occasional constructions is poorly structured and I think needs complete rewrite from scratch to serve as demo in any sense)

cc: @henryiii, @YannickJadoul

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from 933480e to f5976d1 Compare January 10, 2021 19:53
@sizmailov
Copy link
Contributor Author
sizmailov commented Jan 10, 2021

I've moved the CI stubgenc test to a separate workflow restricted to changes in stubgenc-related files, so it won't run for most of the time. The workflow runs misc/test-stubgenc.sh which can also be run locally.

The demo project is updated to be shorter and more structured than what I had before. I think it's already good to be shipped as version 0.0.1. At the moment it's still installed from github and this awaits change to PyPI-install after we agree where the demo project should be named&hosted and who is responsible to maintain it.

@henryiii How do you feel about pybind/pybind11-mypy-demo?
@JukkaL How do you feel about python/pybind11-mypy-demo?

EDIT: CI calls bash script now

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch 4 times, most recently from b14a3cf to d7e7a1e Compare January 10, 2021 20:52
@YannickJadoul
Copy link

When this would be moved under pybind, we should (probably) ask @wjakob, btw. But if there's some good arguments, I don't think that ought to be an issue :-)

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from d7e7a1e to dd87a10 Compare January 12, 2021 16:49
@sizmailov sizmailov marked this pull request as ready for review January 12, 2021 16:50
@sizmailov
Copy link
Contributor Author

I've released pybind11-mypy-demo==0.0.1 on PyPI with number of wheels (thanks to cibuildwheel project!).
I'll happily share write rights (or completely transfer) the project when we will finally decide where it belongs.

At this point I see this PR as complete. I've removed intermediate commits and rebased on current master (which already fixed one the typos from PR :-)
The test-stubgen.sh tests against 0.0.1 version of demo project, so it's completely safe to merge.

@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from dd87a10 to c975b75 Compare January 15, 2021 06:59
@sizmailov sizmailov force-pushed the stubgenc-fixes-and-typos branch from c975b75 to d8f365a Compare January 15, 2021 15:55
@sizmailov
Copy link
Contributor Author

Hi! Is there is anything left that blocks the PR? Do we wait for rights share/transfer, etc.?

It's fine if it's just lack of time :) No rush

@JelleZijlstra JelleZijlstra merged commit 3442b70 into python:master Jan 20, 2021
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
0