Improve auto-generated documentation and type stubs#1413
Conversation
- Use `bytes` and `str | Path` where appropriate. - Extend the type stub generation to generate the full enum definitions and define `Operation` and `Introspect`. - Extend the type stub with more operations (all apart from nifti-based ones).
|
This is very cool @KurtBoehm! I'll try to review this week. Yes, nifti is surprisingly difficult to build :( I leave it out of the flatpak and win builds as well, it's just too annoying. |
…nd pyright - Create a separate stub for `enums.py` to support importing these separately. - Properly type the NumPy functions, which mypy and pyright ignore is NumPy is not available. - Add the missing trigonometric, exponential, and complex operations. - Force keyword arguments to be keyword arguments. - Type `interpolate` as `Interpolate`, not the overly broad `GObject`. - Introduce type aliases to reduce duplication. - Make very minor adjustments elsewhere to avoid mypy errors.
|
Since nothing seems to have happened since my last commit and I have noticed more issues/limitations with the type stubs, I have added many further improvements (most are listed in the commit message). If you are okay with this, I propose splitting the large Since the type stubs require Python 3.10+, and Python 3.9 has reached end-of-life anyway, I switched the CI PyPy version to 3.10 (PyPy 3.11 appears to be incompatible with Ubuntu 22.04). |
This PR introduces several improvements to the typing in the documentation and the type stubs:
bytesas the type of buffers (which is actually what functions such aspngsave_bufferreturn) andstr | Pathfor file names (which were typed as juststruntil now, but the helper function converting strings to bytes already handlespathlib.Path).OperationandIntrospect.The only remaining limitation of the
Imagetype stubs is the lack of nifti operations, as I was not able to install libniftiio on Arch Linux in a way that libvips recognized during compilation (and I did not really want to spend more time on installing it).