Skip to content

Commit c3631c7

Browse files
[ty] Add docstrings for ty_extensions functions (#21036)
Co-authored-by: David Peter <[email protected]>
1 parent 589e8ac commit c3631c7

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

crates/ty_vendored/ty_extensions/ty_extensions.pyi

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: PYI021
12
import sys
23
from collections.abc import Iterable
34
from enum import Enum
@@ -58,12 +59,36 @@ def negated_range_constraint(
5859
#
5960
# Ideally, these would be annotated using `TypeForm`, but that has not been
6061
# 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."""
6792

6893
# Returns the generic context of a type as a tuple of typevars, or `None` if the
6994
# type is not generic.

0 commit comments

Comments
 (0)