@@ -115,7 +115,7 @@ Note that ``None`` as a type hint is a special case and is replaced by
115
115
NewType
116
116
=======
117
117
118
- Use the :class: `NewType ` helper class to create distinct types::
118
+ Use the :class: `NewType ` helper to create distinct types::
119
119
120
120
from typing import NewType
121
121
@@ -144,7 +144,7 @@ accidentally creating a ``UserId`` in an invalid way::
144
144
145
145
Note that these checks are enforced only by the static type checker. At runtime,
146
146
the statement ``Derived = NewType('Derived', Base) `` will make ``Derived `` a
147
- class that immediately returns whatever parameter you pass it. That means
147
+ callable that immediately returns whatever parameter you pass it. That means
148
148
the expression ``Derived(some_value) `` does not create a new class or introduce
149
149
much overhead beyond that of a regular function call.
150
150
@@ -232,7 +232,7 @@ respectively.
232
232
See :pep: `612 ` for more information.
233
233
234
234
.. seealso ::
235
- The documentation for :class: `ParamSpec ` and :class: `Concatenate ` provide
235
+ The documentation for :class: `ParamSpec ` and :class: `Concatenate ` provides
236
236
examples of usage in ``Callable ``.
237
237
238
238
.. _generics :
@@ -401,7 +401,7 @@ to this is that a list of types can be used to substitute a :class:`ParamSpec`::
401
401
Furthermore, a generic with only one parameter specification variable will accept
402
402
parameter lists in the forms ``X[[Type1, Type2, ...]] `` and also
403
403
``X[Type1, Type2, ...] `` for aesthetic reasons. Internally, the latter is converted
404
- to the former and are thus equivalent::
404
+ to the former, so the following are equivalent::
405
405
406
406
>>> class X(Generic[P]): ...
407
407
...
@@ -505,7 +505,7 @@ manner. Use :data:`Any` to indicate that a value is dynamically typed.
505
505
Nominal vs structural subtyping
506
506
===============================
507
507
508
- Initially :pep: `484 ` defined Python static type system as using
508
+ Initially :pep: `484 ` defined the Python static type system as using
509
509
*nominal subtyping *. This means that a class ``A `` is allowed where
510
510
a class ``B `` is expected if and only if ``A `` is a subclass of ``B ``.
511
511
@@ -756,7 +756,6 @@ These can be used as types in annotations using ``[]``, each having a unique syn
756
756
757
757
def with_lock(f: Callable[Concatenate[Lock, P], R]) -> Callable[P, R]:
758
758
'''A type-safe decorator which provides a lock.'''
759
- global my_lock
760
759
def inner(*args: P.args, **kwargs: P.kwargs) -> R:
761
760
# Provide the lock as the first argument.
762
761
return f(my_lock, *args, **kwargs)
@@ -912,7 +911,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn
912
911
``no_type_check `` functionality that currently exists in the ``typing ``
913
912
module which completely disables typechecking annotations on a function
914
913
or a class, the ``Annotated `` type allows for both static typechecking
915
- of ``T `` (e.g., via mypy or Pyre, which can safely ignore ``x ``)
914
+ of ``T `` (which can safely ignore ``x ``)
916
915
together with runtime access to ``x `` within a specific application.
917
916
918
917
Ultimately, the responsibility of how to interpret the annotations (if
@@ -1016,7 +1015,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn
1016
1015
2. If the return value is ``True ``, the type of its argument
1017
1016
is the type inside ``TypeGuard ``.
1018
1017
1019
- For example::
1018
+ For example::
1020
1019
1021
1020
def is_str_list(val: List[object]) -> TypeGuard[List[str]]:
1022
1021
'''Determines whether all objects in the list are strings'''
@@ -1230,11 +1229,11 @@ These are not used in annotations. They are building blocks for creating generic
1230
1229
use a :class: `TypeVar ` with bound ``Callable[..., Any] ``. However this
1231
1230
causes two problems:
1232
1231
1233
- 1. The type checker can't type check the ``inner `` function because
1234
- ``*args `` and ``**kwargs `` have to be typed :data: `Any `.
1235
- 2. :func: `~cast ` may be required in the body of the ``add_logging ``
1236
- decorator when returning the ``inner `` function, or the static type
1237
- checker must be told to ignore the ``return inner ``.
1232
+ 1. The type checker can't type check the ``inner `` function because
1233
+ ``*args `` and ``**kwargs `` have to be typed :data: `Any `.
1234
+ 2. :func: `~cast ` may be required in the body of the ``add_logging ``
1235
+ decorator when returning the ``inner `` function, or the static type
1236
+ checker must be told to ignore the ``return inner ``.
1238
1237
1239
1238
.. attribute :: args
1240
1239
.. attribute :: kwargs
@@ -1392,7 +1391,7 @@ These are not used in annotations. They are building blocks for declaring types.
1392
1391
The resulting class has an extra attribute ``__annotations__ `` giving a
1393
1392
dict that maps the field names to the field types. (The field names are in
1394
1393
the ``_fields `` attribute and the default values are in the
1395
- ``_field_defaults `` attribute both of which are part of the namedtuple
1394
+ ``_field_defaults `` attribute, both of which are part of the :func: ` ~collections. namedtuple`
1396
1395
API.)
1397
1396
1398
1397
``NamedTuple `` subclasses can also have docstrings and methods::
@@ -1467,7 +1466,7 @@ These are not used in annotations. They are building blocks for declaring types.
1467
1466
Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})
1468
1467
1469
1468
The functional syntax should also be used when any of the keys are not valid
1470
- :ref: `identifiers `, for example because they are keywords or contain hyphens.
1469
+ :ref: `identifiers < identifiers > `, for example because they are keywords or contain hyphens.
1471
1470
Example::
1472
1471
1473
1472
# raises SyntaxError
@@ -1506,7 +1505,7 @@ These are not used in annotations. They are building blocks for declaring types.
1506
1505
y: int
1507
1506
z: int
1508
1507
1509
- A ``TypedDict `` cannot inherit from a non-TypedDict class,
1508
+ A ``TypedDict `` cannot inherit from a non-\ `` TypedDict `` class,
1510
1509
notably including :class: `Generic `. For example::
1511
1510
1512
1511
class X(TypedDict):
@@ -1915,7 +1914,7 @@ Corresponding to other types in :mod:`collections.abc`
1915
1914
1916
1915
.. class :: Hashable
1917
1916
1918
- An alias to :class: `collections.abc.Hashable `
1917
+ An alias to :class: `collections.abc.Hashable `.
1919
1918
1920
1919
.. class :: Reversible(Iterable[T_co])
1921
1920
@@ -1927,7 +1926,7 @@ Corresponding to other types in :mod:`collections.abc`
1927
1926
1928
1927
.. class :: Sized
1929
1928
1930
- An alias to :class: `collections.abc.Sized `
1929
+ An alias to :class: `collections.abc.Sized `.
1931
1930
1932
1931
Asynchronous programming
1933
1932
""""""""""""""""""""""""
@@ -2132,7 +2131,7 @@ Functions and decorators
2132
2131
...
2133
2132
class Sub(Base):
2134
2133
def done(self) -> None: # Error reported by type checker
2135
- ...
2134
+ ...
2136
2135
2137
2136
@final
2138
2137
class Leaf:
@@ -2293,8 +2292,8 @@ Constant
2293
2292
2294
2293
If ``from __future__ import annotations `` is used in Python 3.7 or later,
2295
2294
annotations are not evaluated at function definition time.
2296
- Instead, they are stored as strings in ``__annotations__ ``,
2297
- This makes it unnecessary to use quotes around the annotation.
2295
+ Instead, they are stored as strings in ``__annotations__ ``.
2296
+ This makes it unnecessary to use quotes around the annotation
2298
2297
(see :pep: `563 `).
2299
2298
2300
2299
.. versionadded :: 3.5.2
0 commit comments