Skip to content

Commit

Permalink
beartype.math API.
Browse files Browse the repository at this point in the history
This commit by Harvard microscopist and general genius @tlambert03
defines a new public `beartype.math` subpackage for performing type
hint arithmetic, resolving issues #133 and #138 kindly also submitted
by @tlambert03. Specifically, this commit defines a:

* Public `beartype.math.TypeHint({type_hint})` class, enabling rich
  comparisons between pairs of arbitrary type hints. Altogether, this
  class implements a partial ordering over the countably infinite set
  of all type hints. Pedagogical excitement ensues.
* Public `beartype.math.is_subtype({type_hint_a}, {type_hint_b})`
  class, enabling @beartype users to decide whether any type hint
  is a **subtype** (i.e., narrower type hint) of any other type hint.

Thanks so much to @tlambert03 for his phenomenal work here.
(*Compelling compulsion of propulsive propellers!*)
  • Loading branch information
tlambert03 committed Jul 6, 2022
1 parent a23d0d8 commit 7809ea2
Show file tree
Hide file tree
Showing 6 changed files with 1,212 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beartype/_data/hint/pep/sign/datapepsigns.py
Expand Up @@ -97,7 +97,7 @@
HintSignAsyncIterable = _HintSign(name='Iterable')
HintSignCoroutine = _HintSign(name='Coroutine')
HintSignCollection = _HintSign(name='Collection')
HintSignAsyncGenerator = _HintSign(name='Generator')
HintSignAsyncGenerator = _HintSign(name='AsyncGenerator')
HintSignAsyncContextManager = _HintSign(name='ContextManager')

# Structural checks, a.k.a. protocols.
Expand Down
3 changes: 3 additions & 0 deletions beartype/math/__init__.py
@@ -0,0 +1,3 @@
from beartype.math._mathcls import TypeHint, is_subtype

__all__ = ['TypeHint', 'is_subtype']

0 comments on commit 7809ea2

Please sign in to comment.