@@ -1726,11 +1726,11 @@ without the dedicated syntax, as documented below.
1726
1726
class Sequence[T]: # T is a TypeVar
1727
1727
...
1728
1728
1729
- This syntax can also be used to create bound and constrained type
1729
+ This syntax can also be used to create bounded and constrained type
1730
1730
variables::
1731
1731
1732
- class StrSequence[S: str]: # S is a TypeVar bound to str
1733
- ...
1732
+ class StrSequence[S: str]: # S is a TypeVar with a ` str` upper bound;
1733
+ ... # we can say that S is "bounded by `str`"
1734
1734
1735
1735
1736
1736
class StrOrBytesSequence[A: (str, bytes)]: # A is a TypeVar constrained to str or bytes
@@ -1763,8 +1763,8 @@ without the dedicated syntax, as documented below.
1763
1763
"""Add two strings or bytes objects together."""
1764
1764
return x + y
1765
1765
1766
- Note that type variables can be *bound *, *constrained *, or neither, but
1767
- cannot be both bound *and * constrained.
1766
+ Note that type variables can be *bounded *, *constrained *, or neither, but
1767
+ cannot be both bounded *and * constrained.
1768
1768
1769
1769
The variance of type variables is inferred by type checkers when they are created
1770
1770
through the :ref: `type parameter syntax <type-params >` or when
@@ -1774,8 +1774,8 @@ without the dedicated syntax, as documented below.
1774
1774
By default, manually created type variables are invariant.
1775
1775
See :pep: `484 ` and :pep: `695 ` for more details.
1776
1776
1777
- Bound type variables and constrained type variables have different
1778
- semantics in several important ways. Using a *bound * type variable means
1777
+ Bounded type variables and constrained type variables have different
1778
+ semantics in several important ways. Using a *bounded * type variable means
1779
1779
that the ``TypeVar `` will be solved using the most specific type possible::
1780
1780
1781
1781
x = print_capitalized('a string')
@@ -1789,8 +1789,8 @@ without the dedicated syntax, as documented below.
1789
1789
1790
1790
z = print_capitalized(45) # error: int is not a subtype of str
1791
1791
1792
- Type variables can be bound to concrete types , abstract types (ABCs or
1793
- protocols ), and even unions of types::
1792
+ The upper bound of a type variable can be a concrete type , abstract type
1793
+ (ABC or Protocol ), or even a union of types::
1794
1794
1795
1795
# Can be anything with an __abs__ method
1796
1796
def print_abs[T: SupportsAbs](arg: T) -> None:
@@ -1834,7 +1834,7 @@ without the dedicated syntax, as documented below.
1834
1834
1835
1835
.. attribute :: __bound__
1836
1836
1837
- The bound of the type variable, if any.
1837
+ The upper bound of the type variable, if any.
1838
1838
1839
1839
.. versionchanged :: 3.12
1840
1840
@@ -2060,7 +2060,7 @@ without the dedicated syntax, as documented below.
2060
2060
return x + y
2061
2061
2062
2062
Without ``ParamSpec ``, the simplest way to annotate this previously was to
2063
- use a :class: `TypeVar ` with bound ``Callable[..., Any] ``. However this
2063
+ use a :class: `TypeVar ` with upper bound ``Callable[..., Any] ``. However this
2064
2064
causes two problems:
2065
2065
2066
2066
1. The type checker can't type check the ``inner `` function because
0 commit comments