@@ -1609,11 +1609,11 @@ without the dedicated syntax, as documented below.
1609
1609
class Sequence[T]: # T is a TypeVar
1610
1610
...
1611
1611
1612
- This syntax can also be used to create bound and constrained type
1612
+ This syntax can also be used to create bounded and constrained type
1613
1613
variables::
1614
1614
1615
- class StrSequence[S: str]: # S is a TypeVar bound to str
1616
- ...
1615
+ class StrSequence[S: str]: # S is a TypeVar with a ` str` upper bound;
1616
+ ... # we can say that S is "bounded by `str`"
1617
1617
1618
1618
1619
1619
class StrOrBytesSequence[A: (str, bytes)]: # A is a TypeVar constrained to str or bytes
@@ -1646,8 +1646,8 @@ without the dedicated syntax, as documented below.
1646
1646
"""Add two strings or bytes objects together."""
1647
1647
return x + y
1648
1648
1649
- Note that type variables can be *bound *, *constrained *, or neither, but
1650
- cannot be both bound *and * constrained.
1649
+ Note that type variables can be *bounded *, *constrained *, or neither, but
1650
+ cannot be both bounded *and * constrained.
1651
1651
1652
1652
The variance of type variables is inferred by type checkers when they are created
1653
1653
through the :ref: `type parameter syntax <type-params >` or when
@@ -1657,8 +1657,8 @@ without the dedicated syntax, as documented below.
1657
1657
By default, manually created type variables are invariant.
1658
1658
See :pep: `484 ` and :pep: `695 ` for more details.
1659
1659
1660
- Bound type variables and constrained type variables have different
1661
- semantics in several important ways. Using a *bound * type variable means
1660
+ Bounded type variables and constrained type variables have different
1661
+ semantics in several important ways. Using a *bounded * type variable means
1662
1662
that the ``TypeVar `` will be solved using the most specific type possible::
1663
1663
1664
1664
x = print_capitalized('a string')
@@ -1672,8 +1672,8 @@ without the dedicated syntax, as documented below.
1672
1672
1673
1673
z = print_capitalized(45) # error: int is not a subtype of str
1674
1674
1675
- Type variables can be bound to concrete types , abstract types (ABCs or
1676
- protocols ), and even unions of types::
1675
+ The upper bound of a type variable can be a concrete type , abstract type
1676
+ (ABC or Protocol ), or even a union of types::
1677
1677
1678
1678
# Can be anything with an __abs__ method
1679
1679
def print_abs[T: SupportsAbs](arg: T) -> None:
@@ -1717,7 +1717,7 @@ without the dedicated syntax, as documented below.
1717
1717
1718
1718
.. attribute :: __bound__
1719
1719
1720
- The bound of the type variable, if any.
1720
+ The upper bound of the type variable, if any.
1721
1721
1722
1722
.. versionchanged :: 3.12
1723
1723
@@ -1903,7 +1903,7 @@ without the dedicated syntax, as documented below.
1903
1903
return x + y
1904
1904
1905
1905
Without ``ParamSpec ``, the simplest way to annotate this previously was to
1906
- use a :class: `TypeVar ` with bound ``Callable[..., Any] ``. However this
1906
+ use a :class: `TypeVar ` with upper bound ``Callable[..., Any] ``. However this
1907
1907
causes two problems:
1908
1908
1909
1909
1. The type checker can't type check the ``inner `` function because
0 commit comments