Skip to content

Tracker: Differences with NumPy #392

@jorenham

Description

@jorenham

This is a temporary tracker issue for the major differences between the stubs provided by NumType, and those bundled with NumPy. Once the documentation is online, a dedicated page for these will be created, instead.


Backwards incompatible fixes

Scalar type methods

Concrete scalar types

Extended precision

NBitBase

Quality assurance

API consistency

Unlike NumPy, NumType uses stubtest to ensure that the typing stubs match the runtime implementation.

Type-checkers

The stubs in NumType are also checked by mypy, pyright, and basedpyright (in strict mode) to avoid any errors, and ensure compatibility with the major type-checkers.

Testing

NumPy uses a manual type-testing strategy, and its type-tests are a collection of toy examples that should either be rejected, accepted, or inferred to be of specific type using typing.assert_type.
But there is no mechanism that validates whether these type-tests correctly describe what would happen at runtime. The only way to ensure correctness of these tests, is to manually verify them. In NumPy, the type-tests are evaluated using mypy.

NumType also uses most of NumPy's (manual) type-tests, but validates them with both mypy and basedpyright.
But unlike NumPy, NumType also uses test generation in several places. For the scalar binary operators such as int8.__add__, for example, NumType procedurally generates all possible combinations of scalar types and operators, resulting in a 8283 assert_type statements and 2655 expected rejections. This guarantees that the scalar operator method annotations are correct and accurate for all possible (scalar) input types.

New features

Optional dtype type parameter

The generic scalar-type parameter of numpy.dtype has been made optional, with Any as the default. This allows you to write _: np.dtype instead of _: np.dtype[Any].

The numtype package

TBD

Shape-typing

TBD

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions