Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This release brings undeniable support for **typed NumPy arrays** (i.e., `numpy.typed.NDArray` type hints), **typing backports** (i.e., public public attributes of the third-party `typing_extensions` package, enabling typing_ types introduced by newer Python versions to be used under older Python versions), and **portable beartype validators** (i.e., `beartype.vale` type hints usable under *all* Python versions via the `typing_extensions.Annotated` backport). This release resolves **4 issues** and merges **2 pull requests.** Changes include: ## Compatibility Improved * **Typed NumPy arrays** (i.e., `numpy.typed.NDArray` type hints). The `@beartype` decorator now transparently supports the third-party `numpy.typing.NDArray` type hint newly introduced by NumPy >= 1.21.0, resolving issue #42 kindly submitted by NumPy extraordinaire @Antyos. Note that usage of typed NumPy arrays under Python < 3.9.0 requires installation of the third-party `typing-extensions` package, which `@beartype` will then automagically detect and leverage internally. * **Typing backports** (i.e., `typing_extensions` type hints). The `@beartype` decorator now transparently supports all public type hints of the third-party `typing_extensions` package, resolving issue #34 kindly submitted by Ryan Soklaski (@rsokl) of considerable *MIT Beaver Works Summer Institute* and *Python Like You Mean It* fame. Note that usage of typed NumPy arrays under Python < 3.9.0 requires installation of the third-party `typing-extensions` package, which `@beartype` will then automagically detect and leverage internally. * **Python < 3.9.0 beartype validators.** The `@beartype` decorator now portably supports **beartype validators** (i.e., `beartype.vale` objects annotating `typing{_extensions}.Annotated` type hints) across all Python versions, *also* resolving issue #34 kindly submitted by Ryan Soklaski (@rsokl). <sup>hallowed be his username</sup> Note that usage of beartype validators under Python < 3.9.0 requires: * Installation of the third-party `typing-extensions` package. * Annotation of `beartype.vale` objects by `typing_extensions.Annotated` (rather than `typing.Annotated`). * **Python >= 3.10.0 `typing.NewType` type hints.** This release resolves a minor incompatibility recently introduced by Python 3.10.0rc1, which (*waitforit*) broke backward compatibility with prior implementations of the public `typing.NewType` type hint. Previously, that hint was implemented as a closure; Python ≥ 3.10 fundamentally refactored that hint to a pure-Python class instance – significantly complicating cross-version detection. *yuwastemytime,* CPython? * **Binary dunder method return annotations** (i.e., dunder methods accepting exactly two arguments). Previously, `@beartype` adopted mypy's permissive approach of implicitly coercing the return annotations of binary dunder methods returning only booleans to instead return `typing.Union[bool, type(NotImplemented)]`. `beartype` now expands that approach to *all* binary dunder methods regardless of return annotation. Thanks to pull request #40 from Matt Bogosian (@posita), Dropbox's positive code genius! ## Compatibility Broken * **None.** This release preserves backward compatibility with the prior stable release. ## Issues Resolved * **#44,** documenting beartype's new project shield generously ginned up by Matt Bogosian (@posita), Dropbox's positive code genius. * **#42,** enabling typed NumPy arrays to be used under both Python ≥ 3.9.0 natively *and* Python < 3.9.0 via the `typing_extensions.Annotated` backport. * **#40,** including: * **Fake builtin types** (i.e., non-builtin classes erroneously masquerading as builtin). Previously, `@beartype` incorrectly generated syntactically invalid code for decorated callables annotated by one or more fake builtin types – which, miraculously, there are hardly any of. Still... *it's not a good look, beartype.* Thanks to Matt Bogosian (@posita), Dropbox's positive code genius, for first detecting this horrifying edge case in pull request #40. * **#34,** enabling beartype validators to be used under Python < 3.9.0 via the `typing_extensions.Annotated` backport. ## Documentation Revised * **Badge** (i.e., shield intended for display by downstream projects). Our front-facing `README.rst` documentation now provides a post-installation advisory suggesting public declaration of @beartype project compatibility with reST- and Markdown-friendly text exhibiting a beautiful @beartype badge. Unsurprisingly, @posita made that too... because what doesn't @posita do? Nuthin'! I'm pretty sure that means @posita does everything. ## Tests Improved * **Optional dependencies.** Our GitHub Actions-based continuous integration (CI) configuration now installs optional test-time dependencies. Although `beartype` has *no* mandatory runtime dependencies, fully exercising all tests necessitates installing these test-time dependencies: * mypy, enabling tests for mypy-based PEP 561 compliance. * NumPy, enabling tests for `numpy.typing.NDArray` type hints. This proved surprisingly non-trivial. Apple's patently broken "Accelerate" BLAS replacement (as documented at numpy/numpy#15947) blocks NumPy ≥ 1.18.0 installation under default CI configurations, necessitating that we: * Only conditionally install `pip` packages with `--force-reinstall` under macOS. CI gonna CI. * Avoid installing NumPy altogether under macOS + PyPy, where even the `--force-reinstall` option fails to improve matters. You can only do so much when your core platform is fundamentally broken. Thanks, Apple. * `typing_extensions`, enabling tests for `typing` attributes unavailable under the active Python interpreter. Thanks yet again to Badge Connoisseur @posita for his tremendous efforts – which we are now eternally indebted to and can only repay across the span of several gruelling lifetimes. "It will all be worth it," I tell my future self. (*Clogged clogs and unlogged cogs!*)
- Loading branch information