Skip to content

ENH: Refactor the typing "reveal" tests using typing.assert_type #21505

@BvB93

Description

@BvB93

Proposed new feature or change:

Python 3.11 will add the new typing.assert_type function, which is used for validating that two types are equivalent while static type checking. Switching from the type-comments, currently used for validating the revealed type, to typing.assert_type has a number advantages:

  • It finally allows to get rid of the old type-comments, which add a lot of visual clutter.
  • It makes it much easier to use features like type-aliases.
  • typing.assert_type is agnostic w.r.t. the particular type checkers, so this means we could in principle easily run the tests with other type checkers besides mypy.

Note that a backport is already available in typing-extensions and fully supported as of the latest mypy release (0.950).

Examples

AR_c16: NDArray[np.complex128]
AR_c = NDArray[np.complexfloating]

typing.assert_type(np.fft.fftfreq(np.int64(), AR_c16), AR_c)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions