From c3631c78bd94b7afbe4293d3e2555f0c88d0c4ba Mon Sep 17 00:00:00 2001 From: Eric Mark Martin Date: Thu, 23 Oct 2025 03:50:21 -0400 Subject: [PATCH] [ty] Add docstrings for `ty_extensions` functions (#21036) Co-authored-by: David Peter --- .../ty_extensions/ty_extensions.pyi | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/ty_vendored/ty_extensions/ty_extensions.pyi b/crates/ty_vendored/ty_extensions/ty_extensions.pyi index def2cd0963..262ded8867 100644 --- a/crates/ty_vendored/ty_extensions/ty_extensions.pyi +++ b/crates/ty_vendored/ty_extensions/ty_extensions.pyi @@ -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.