Skip to content

Commit

Permalink
**Beartype 0.8.0** released.
Browse files Browse the repository at this point in the history
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
leycec committed Aug 18, 2021
1 parent 7ea1cb0 commit 9909550
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -790,7 +790,7 @@ Filling in the Titanic-sized gaps between `Python's patchwork quilt of PEPs
<Compliance_>`__, validators accelerate your QA workflow with your greatest
asset.
Yup, it's your brain.
Yup. It's your brain.
See `Validator Showcase`_ for comforting examples – or blithely continue for
uncomfortable details you may regret reading.
Expand Down
2 changes: 1 addition & 1 deletion beartype/meta.py
Expand Up @@ -200,7 +200,7 @@ def _convert_version_str_to_tuple(version_str: str) -> _Tuple[int, ...]:
# For further details, see http://semver.org.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

VERSION = '0.7.2'
VERSION = '0.8.0'
'''
Human-readable package version as a ``.``-delimited string.
'''
Expand Down

0 comments on commit 9909550

Please sign in to comment.