|
| 1 | +# ruff: noqa: PYI021 |
1 | 2 | import sys |
2 | 3 | from collections.abc import Iterable |
3 | 4 | from enum import Enum |
@@ -58,12 +59,36 @@ def negated_range_constraint( |
58 | 59 | # |
59 | 60 | # Ideally, these would be annotated using `TypeForm`, but that has not been |
60 | 61 | # standardized yet (https://peps.python.org/pep-0747). |
61 | | -def is_equivalent_to(type_a: Any, type_b: Any) -> ConstraintSet: ... |
62 | | -def is_subtype_of(type_a: Any, type_b: Any) -> ConstraintSet: ... |
63 | | -def is_assignable_to(type_a: Any, type_b: Any) -> ConstraintSet: ... |
64 | | -def is_disjoint_from(type_a: Any, type_b: Any) -> ConstraintSet: ... |
65 | | -def is_singleton(ty: Any) -> bool: ... |
66 | | -def is_single_valued(ty: Any) -> bool: ... |
| 62 | +def is_equivalent_to(type_a: Any, type_b: Any) -> ConstraintSet: |
| 63 | + """Returns a constraint that is satisfied when `type_a` and `type_b` are |
| 64 | + `equivalent`_ types. |
| 65 | +
|
| 66 | + .. _equivalent: https://typing.python.org/en/latest/spec/glossary.html#term-equivalent |
| 67 | + """ |
| 68 | + |
| 69 | +def is_subtype_of(ty: Any, of: Any) -> ConstraintSet: |
| 70 | + """Returns a constraint that is satisfied when `ty` is a `subtype`_ of `of`. |
| 71 | +
|
| 72 | + .. _subtype: https://typing.python.org/en/latest/spec/concepts.html#subtype-supertype-and-type-equivalence |
| 73 | + """ |
| 74 | + |
| 75 | +def is_assignable_to(ty: Any, to: Any) -> ConstraintSet: |
| 76 | + """Returns a constraint that is satisfied when `ty` is `assignable`_ to `to`. |
| 77 | +
|
| 78 | + .. _assignable: https://typing.python.org/en/latest/spec/concepts.html#the-assignable-to-or-consistent-subtyping-relation |
| 79 | + """ |
| 80 | + |
| 81 | +def is_disjoint_from(type_a: Any, type_b: Any) -> ConstraintSet: |
| 82 | + """Returns a constraint that is satisfied when `type_a` and `type_b` are disjoint types. |
| 83 | +
|
| 84 | + Two types are disjoint if they have no inhabitants in common. |
| 85 | + """ |
| 86 | + |
| 87 | +def is_singleton(ty: Any) -> bool: |
| 88 | + """Returns `True` if `ty` is a singleton type with exactly one inhabitant.""" |
| 89 | + |
| 90 | +def is_single_valued(ty: Any) -> bool: |
| 91 | + """Returns `True` if `ty` is non-empty and all inhabitants compare equal to each other.""" |
67 | 92 |
|
68 | 93 | # Returns the generic context of a type as a tuple of typevars, or `None` if the |
69 | 94 | # type is not generic. |
|
0 commit comments