Experiment towards an auto-geneated type stubs package #5472
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This creates a PEP 561 type stubs package which can be published to PyPI, perhaps for use in type-checking in CI without needing to install the whole of Webots.
A core limitation of this approach is that since this is a stubs-only package consumers are still unable to import the Webots classes, meaning that this doesn't provide a solution for writing unit-tests of controller code which imports (but does not use in tests) Webots controllers. This stubs package does not preclude (nor would it interfere with) adding a more complete runtime package on PyPI later. Doing so would likely render this package redundant however.
This is very much a first pas and not at all ready for merge yet. Instead this is intended as a contribution to the conversation around Python type stubs for Webots.
Currently this package produces type checking failures in the test project I have (https://github.com/srobo/competition-simulator/tree/webots-published-stubs) which are not found by the local stubs from the project (removed on the linked branch). I'm not sure if that's a result of the project-local stubs being incorrect, whether the API in Webots has moved on since the last release, whether there are bugs in the type annotations in Webots, or something else.
Included here is a CI job which builds the package and saves it as an artefact. This is mostly so there's an easily available copy of the output.
I did notice that the Python API in Webots doesn't have full type coverage, nor is it itself checked by
mypy
. While those aren't things I'd want this PR to introduce, it would probably be better to have at least the checking bymypy
in place before publishing the stubs package so that the stubs don't themselves contain inconsistencies.Related Issues
Follows from discussion #2385 (comment)
Documentation
This would likely need documentation.
Questions
If so: