mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-03 21:24:29 +00:00
[ty] Add docstrings for ty_extensions functions (#21036)
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
This commit is contained in:
parent
589e8ac0d9
commit
c3631c78bd
1 changed files with 31 additions and 6 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue