Type stubs (PEP 561) for gmpy2 2.2.1: GMP, MPFR, and MPC support.
Project description
gmpy2-stubs
Type stubs for the gmpy2 library (version 2.2.1).
gmpy2 is a C-coded Python extension module that supports multiple-precision arithmetic. It provides access to the GMP (GNU Multiple Precision Arithmetic Library), MPFR (Multiple-Precision Floating-Point Reliable Library), and MPC (Multiple-Precision Complex Library) libraries. gmpy2 itself does not include type hints. This package provides them.
Installation
pip install gmpy2-stubs
or, if you'd like to use a specific version:
pip install gmpy2-stubs==2.2.1.0
Usage
These stubs are automatically used by static type checkers like mypy and pyright when you have both gmpy2 and gmpy2-stubs installed. You do not need to import anything from gmpy2-stubs directly.
import gmpy2
# Type hints are available here!
x = gmpy2.mpz(123)
y = gmpy2.sqrt(x)
print(y)
Limitations: inspect.signature()
It's important to understand that these stubs are designed for static type checking. They will not affect the behavior of runtime introspection tools like inspect.signature().
gmpy2, like many C extension modules, does not provide complete runtime signature information. The standard library's inspect.signature() function relies on information that is usually available for pure Python functions (like docstrings and argument annotations) but is often missing or incomplete for C extensions.
There have been discussions about improving this situation, including:
- gmpy2 issue #496: Type declarations to allow integration with type checking and linting tools - Discusses the general problem and potential solutions (including this stub package!).
- CPython issue #121945: Use *.pyi stub files as source for the inspect.signature() - A proposal to make
inspect.signature()use stub files as a fallback, but this was closed as not planned.
Therefore, if you use inspect.signature() on gmpy2 functions, you will likely get a generic signature (e.g., (*args, **kwargs)) rather than a detailed one. This is a limitation of the current Python introspection mechanisms, not a limitation of these stubs. The stubs will provide full type information to static type checkers.
Contributing
Contributions and improvements to these stubs are very welcome! Please submit pull requests or open issues on the GitHub repository.
License
These stubs are licensed under the MIT License (see the LICENSE file). gmpy2 itself is licensed under the LGPLv3+ license.
Author
David Osipov (personal@david-osipov.vision)
- ISNI: 0000 0005 1802 960X
- ORCID: 0009-0005-2713-9242
- PGP key: https://openpgpkey.david-osipov.vision/.well-known/openpgpkey/david-osipov.vision/D3FC4983E500AC3F7F136EB80E55C4A47454E82E.asc
- PGP fingerprint: D3FC 4983 E500 AC3F 7F13 6EB8 0E55 C4A4 7454 E82E
- Website: https://david-osipov.vision
- LinkedIn: https://www.linkedin.com/in/david-osipov/
Acknowledgements
Thanks to the gmpy2 developers for creating this powerful library!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmpy2_stubs-2.2.1.1.tar.gz.
File metadata
- Download URL: gmpy2_stubs-2.2.1.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d974767a6761288f04e4293c84f0a9114ecd3611a4e60b6d758d7640dc5ab43
|
|
| MD5 |
b7b1a3e62910a696e5d70a8758be96a9
|
|
| BLAKE2b-256 |
35645567adcc3bbed6336e5c9a9fb94c9a9a05ced7091a689ff80400acb6ee0d
|
Provenance
The following attestation bundles were made for gmpy2_stubs-2.2.1.1.tar.gz:
Publisher:
pypi-publish.yml on DavidOsipov/gmpy2-stubs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmpy2_stubs-2.2.1.1.tar.gz -
Subject digest:
6d974767a6761288f04e4293c84f0a9114ecd3611a4e60b6d758d7640dc5ab43 - Sigstore transparency entry: 187103145
- Sigstore integration time:
-
Permalink:
DavidOsipov/gmpy2-stubs@897feb68cc9439889d78317de0a437683b010eae -
Branch / Tag:
refs/tags/2.2.1.1 - Owner: https://github.com/DavidOsipov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@897feb68cc9439889d78317de0a437683b010eae -
Trigger Event:
push
-
Statement type:
File details
Details for the file gmpy2_stubs-2.2.1.1-py3-none-any.whl.
File metadata
- Download URL: gmpy2_stubs-2.2.1.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c6d0a6f1deb74dd7de469c3e88cab6cd6fe47d74d142cedaf3964bb929ad9cb
|
|
| MD5 |
558de51ce7ed718481672bce3ae21b84
|
|
| BLAKE2b-256 |
9f667fc3f337cf40b492ecef82bbb42beb6115ae53846414a6bb256a87e7f817
|
Provenance
The following attestation bundles were made for gmpy2_stubs-2.2.1.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on DavidOsipov/gmpy2-stubs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gmpy2_stubs-2.2.1.1-py3-none-any.whl -
Subject digest:
6c6d0a6f1deb74dd7de469c3e88cab6cd6fe47d74d142cedaf3964bb929ad9cb - Sigstore transparency entry: 187103147
- Sigstore integration time:
-
Permalink:
DavidOsipov/gmpy2-stubs@897feb68cc9439889d78317de0a437683b010eae -
Branch / Tag:
refs/tags/2.2.1.1 - Owner: https://github.com/DavidOsipov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@897feb68cc9439889d78317de0a437683b010eae -
Trigger Event:
push
-
Statement type: