[ty] Add docstrings for ty_extensions functions (#21036)

Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
This commit is contained in:
Eric Mark Martin 2025-10-23 03:50:21 -04:00 committed by GitHub
parent 589e8ac0d9
commit c3631c78bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,3 +1,4 @@
# ruff: noqa: PYI021
import sys
from collections.abc import Iterable
from enum import Enum
@ -58,12 +59,36 @@ def negated_range_constraint(
#
# Ideally, these would be annotated using `TypeForm`, but that has not been
# standardized yet (https://peps.python.org/pep-0747).
def is_equivalent_to(type_a: Any, type_b: Any) -> ConstraintSet: ...
def is_subtype_of(type_a: Any, type_b: Any) -> ConstraintSet: ...
def is_assignable_to(type_a: Any, type_b: Any) -> ConstraintSet: ...
def is_disjoint_from(type_a: Any, type_b: Any) -> ConstraintSet: ...
def is_singleton(ty: Any) -> bool: ...
def is_single_valued(ty: Any) -> bool: ...
def is_equivalent_to(type_a: Any, type_b: Any) -> ConstraintSet:
"""Returns a constraint that is satisfied when `type_a` and `type_b` are
`equivalent`_ types.
.. _equivalent: https://typing.python.org/en/latest/spec/glossary.html#term-equivalent
"""
def is_subtype_of(ty: Any, of: Any) -> ConstraintSet:
"""Returns a constraint that is satisfied when `ty` is a `subtype`_ of `of`.
.. _subtype: https://typing.python.org/en/latest/spec/concepts.html#subtype-supertype-and-type-equivalence
"""
def is_assignable_to(ty: Any, to: Any) -> ConstraintSet:
"""Returns a constraint that is satisfied when `ty` is `assignable`_ to `to`.
.. _assignable: https://typing.python.org/en/latest/spec/concepts.html#the-assignable-to-or-consistent-subtyping-relation
"""
def is_disjoint_from(type_a: Any, type_b: Any) -> ConstraintSet:
"""Returns a constraint that is satisfied when `type_a` and `type_b` are disjoint types.
Two types are disjoint if they have no inhabitants in common.
"""
def is_singleton(ty: Any) -> bool:
"""Returns `True` if `ty` is a singleton type with exactly one inhabitant."""
def is_single_valued(ty: Any) -> bool:
"""Returns `True` if `ty` is non-empty and all inhabitants compare equal to each other."""
# Returns the generic context of a type as a tuple of typevars, or `None` if the
# type is not generic.