Skip to main content

Type stubs (PEP 561) for gmpy2 2.2.1: GMP, MPFR, and MPC support.

Project description

gmpy2-stubs

PyPI version PyPI - Downloads License

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.

IMPORTANT CAVEAT: gmpy2 Runtime Behavior

Please be aware: The underlying gmpy2 library, which these stubs provide type hints for, can crash the Python interpreter in case of memory allocation failure. This is due to the memory management behavior of the wrapped GMP library.

To mitigate this risk when using gmpy2 in your code:

  • Estimate the potential size of calculation results.
  • Prevent or handle calculations that could exhaust available system memory.

Failure to account for this may lead to unexpected program termination.

Installation

pip install gmpy2-stubs

or, if you'd like to use a specific version:

pip install gmpy2-stubs==2.2.1.2

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:

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)

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

gmpy2_stubs-2.2.1.2.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmpy2_stubs-2.2.1.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file gmpy2_stubs-2.2.1.2.tar.gz.

File metadata

  • Download URL: gmpy2_stubs-2.2.1.2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gmpy2_stubs-2.2.1.2.tar.gz
Algorithm Hash digest
SHA256 5e043b2da5b3ce20f9ce5d29d4d48caeb1f882a33d175f24469da26501337dfa
MD5 ae570df06263ff18551dc7953ebe27d0
BLAKE2b-256 5e2a0d0a103e1579ce670b4647c68588971ccf4d601ab1831f25ed0b4d856dfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmpy2_stubs-2.2.1.2.tar.gz:

Publisher: pypi-publish.yml on DavidOsipov/gmpy2-stubs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gmpy2_stubs-2.2.1.2-py3-none-any.whl.

File metadata

  • Download URL: gmpy2_stubs-2.2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gmpy2_stubs-2.2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 554ab8b45dfbb9e82908f2da4b3c5e3feac4bf7a7ed0e1bb2d987e9e1e0adf17
MD5 7ea3dd40ff8aa2ed0c365dbf69197c5a
BLAKE2b-256 b8daf7138b7102d37a6aa47ac8643fcd7b291b73fcccf601f638e60be682f101

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmpy2_stubs-2.2.1.2-py3-none-any.whl:

Publisher: pypi-publish.yml on DavidOsipov/gmpy2-stubs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page