VOOZH about

URL: https://pypi.org/project/numpy-typing-compat/

โ‡ฑ numpy-typing-compat ยท PyPI


Skip to main content

numpy-typing-compat 20260602.2.5

pip install numpy-typing-compat

Latest release

Released:

Static typing compatibility layer for older versions of NumPy

Navigation

Verified details

These details have been verified by PyPI
Project links
GitHub Statistics
Maintainers
๐Ÿ‘ Avatar for jhammudoglu from gravatar.com
jhammudoglu ๐Ÿ‘ Avatar for rgommers from gravatar.com
rgommers
Meta

Unverified details

These details have not been verified by PyPI
Meta
  • License Expression: BSD-3-Clause
    SPDX License Expression
  • Author: Joren Hammudoglu
  • Tags numpy , optype , typing , compatibility
  • Requires: Python >=3.12

Project description

numpy-typing-compat

๐Ÿ‘ release
๐Ÿ‘ Conda Downloads
๐Ÿ‘ typed
๐Ÿ‘ license
๐Ÿ‘ NumPy

Overview

This package provides version-specific boolean constants that allow library authors to write NumPy-version-dependent static type annotations. Similar to how you might use if sys.version_info >= (3, 12): for Python version checks, numpy-typing-compat enables static type-checkers to understand which NumPy version is being used and apply appropriate type annotations.

[!TIP] numpy-typing-compat is intended as a helper package for the optype library, which provides high-level typing utilities for annotating NumPy operations. In most situations, it is recommended to use optype instead of numpy-typing-compat. See the optype.numpy documentation for more details.

Installation and Versioning

The numpy-typing-compat packages are available on PyPI and conda-forge.

Modern package managers such as uv and pixi will automatically install the appropriate version of numpy-typing-compat that matches your installed NumPy version, in order to satisfy the numpy dependency restrictions of numpy-typing-compat.

[!WARNING] Legacy package managers such as pip don't always respect dependency restrictions. Running pip install --upgrade numpy will not automatically upgrade numpy-typing-compat to the correct version. If for some reason you need to use pip, then be sure to manually install the correct version of numpy-typing-compat that matches your installed NumPy version. Running pip check will tell you whether the installed numpy-typing-compat and numpy versions are compatible.

To illustrate, the numpy-typing-compat==20250818.2.1 distribution of release v20250818 specifies numpy>=2.1,<2.2 as a required dependency. Modern package managers will ensure that these dependency restrictions are satisfied. That way, if you upgrade numpy from 2.1 to 2.3 (e.g. by running uv sync --upgrade) then uv will also automatically look for a version of numpy-typing-compat that satisfies the new numpy version, which for this example would be numpy-typing-compat==20250818.2.3.

numpy-typing-compat NumPy Python
20251206.2.0 >=2.0,<2.1 >=3.10
20251206.2.1 >=2.1,<2.2 >=3.10
20251206.2.2 >=2.2,<2.3 >=3.10
20251206.2.3 >=2.3,<2.4 >=3.11
20251206.2.4 >=2.4,<2.5 >=3.11

Reference

StringDType

In NumPy 2.0, the numpy.dtypes.StringDType was introduced, but it wasn't until NumPy 2.1 that it was also available in the numpy stubs. The numpy_typing_compat.StringDType is a re-export of numpy.dtypes.StringDType on numpy >= 2.1, and an alias of np.dtype[Never] on numpy < 2.1. This allows type checkers to also accept StringDType as a valid type on numpy == 2.0.*.

ABCPolyBase

In NumPy 2.1, the numpy.polynomial._polybase.ABCPolyBase was made into a generic type, and in NumPy 2.2 the type parameter was made optional. This can be problematic on numpy==2.1.* if you also require support for numpy < 2.1. To work around this, the numpy_typing_compat.ABCPolyBase is a type alias for numpy.polynomial._polybase.ABCPolyBase[LiteralString | None] on numpy==2.1.*, and a direct re-export of numpy.polynomial._polybase.ABCPolyBase otherwise. This way, type checkers (when configured in strict mode) won't report an error on numpy==2.1.* when using ABCPolyBase. Note that numpy_typing_compat.ABCPolyBase does not accept a type parameter, even on numpy >= 2.1, for the sake of consistency.

LiteralTrue and LiteralFalse

In NumPy 2.2, the np.bool scalar type became a generic type that accepts a type parameter of either True or False. For compatibility with numpy < 2.2, the numpy_typing_compat.LiteralTrue and numpy_typing_compat.LiteralFalse types are provided. These are type aliases for Literal[True] and Literal[False] on numpy < 2.2, and Literal[True] | np.bool[Literal[True]] and Literal[False] | np.bool[Literal[False]] on numpy >= 2.2, respectively.

Version constants

The following low-level boolean version constants are available:

Constant True when
NUMPY_GE_2_0 numpy >= 2.0
NUMPY_GE_2_1 numpy >= 2.1
NUMPY_GE_2_2 numpy >= 2.2
NUMPY_GE_2_3 numpy >= 2.3
NUMPY_GE_2_4 numpy >= 2.4

Each constant is typed as Literal[True] or Literal[False] depending on your NumPy version, so that static type-checkers are able to understand the NumPy version being used.

[!WARNING] At the moment, mypy and pyright only have limited support for Literal type conditions, and will not treat if NUMPY_GE_2_0: ... in the same way as if sys.version_info >= (3, 12): ... or if sys.platform == "win32": ....

Project details

Verified details

These details have been verified by PyPI
Project links
GitHub Statistics
Maintainers
๐Ÿ‘ Avatar for jhammudoglu from gravatar.com
jhammudoglu ๐Ÿ‘ Avatar for rgommers from gravatar.com
rgommers
Meta

Unverified details

These details have not been verified by PyPI
Meta
  • License Expression: BSD-3-Clause
    SPDX License Expression
  • Author: Joren Hammudoglu
  • Tags numpy , optype , typing , compatibility
  • Requires: Python >=3.12

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numpy_typing_compat-20260602.2.5.tar.gz (4.6 kB view details)

Uploaded Source

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

numpy_typing_compat-20260602.2.5-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file numpy_typing_compat-20260602.2.5.tar.gz.

File metadata

File hashes

Hashes for numpy_typing_compat-20260602.2.5.tar.gz
Algorithm Hash digest
SHA256 1885a678e9a24564839ed5d1711c0031735fb7de7f0b5ed88d550e5d45a8d4f9
MD5 8147c01ac8b560e04f11a855becbf925
BLAKE2b-256 08db5cd1d99caea4bf39fd477686ded4b9b70dff3c7673b5d84ef2d96a4f5aab

See more details on using hashes here.

Provenance

The following attestation bundles were made for numpy_typing_compat-20260602.2.5.tar.gz:

Publisher: publish-pypi.yml on jorenham/numpy-typing-compat

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

File details

Details for the file numpy_typing_compat-20260602.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for numpy_typing_compat-20260602.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 21ba7757c8924d359a9ed3ab2163c282a70983ae64498fdba6d1892a6641c8b1
MD5 539491f75e0af499a7e56be44b65f0e0
BLAKE2b-256 b1a49376b38b7387a0296b1f626b966e5503578625c9673777db1b45bf70acb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for numpy_typing_compat-20260602.2.5-py3-none-any.whl:

Publisher: publish-pypi.yml on jorenham/numpy-typing-compat

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

Supported by

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