aleaxit / gmpy

General Multi-Precision arithmetic for Python 2.6+/3+ (GMP, MPIR, MPFR, MPC)
https://gmpy2.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
518 stars 86 forks source link

Type declarations to allow integration with type checking and linting tools #496

Open SkwalExe opened 3 months ago

SkwalExe commented 3 months ago

I use Gmpy2 in several projects, and I've found it difficult to integrate the library with type checking and linting tools such as Ruff or Pyright. The main issue is that the PyPI package doesn't include type declarations (.pyi files).

Do you have any plans to publish type declaration files with the package, or make them available through another channel? Or is there another way to perform linting and type checking on projects using gmpy2? I am surprised that this issue has not been discussed, since type checking and linting are very important to any projects.

skirpichev commented 3 months ago

I was planing to add support for return annotations in the __text_signature__. That will allow to describe typing information via docstring. Now this works with the sphinx (see e.g. this), but that information isn't available for introspection with inspect module, for type checkers, etc.

Here is the d.p.o thread: https://discuss.python.org/t/type-signatures-for-extension-modules-pep-draft/43914

One suggestion was: support *.pyi files as a source for the inspect module. Maybe someday I'll find a time to create a feature request.

So, I think *.pyi stub files - a good thing to have.

skirpichev commented 3 months ago

See https://github.com/python/cpython/issues/121945, however.