Skip to content

Commit fdba3cd

Browse files
authored
docs: miscellaneous improvements (#9762)
Co-authored-by: hauntsaninja <>
1 parent 109d05e commit fdba3cd

9 files changed

+31
-99
lines changed

docs/source/builtin_types.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ strings and ``Dict[Any, Any]`` is a dictionary of dynamically typed
3131
(arbitrary) values and keys. ``List`` is another generic class. ``Dict`` and
3232
``List`` are aliases for the built-ins ``dict`` and ``list``, respectively.
3333

34-
``Iterable``, ``Sequence``, and ``Mapping`` are generic types that
35-
correspond to Python protocols. For example, a ``str`` object or a
36-
``List[str]`` object is valid
37-
when ``Iterable[str]`` or ``Sequence[str]`` is expected. Note that even though
38-
they are similar to abstract base classes defined in :py:mod:`collections.abc`
39-
(formerly ``collections``), they are not identical, since the built-in
40-
collection type objects do not support indexing.
34+
``Iterable``, ``Sequence``, and ``Mapping`` are generic types that correspond to
35+
Python protocols. For example, a ``str`` object or a ``List[str]`` object is
36+
valid when ``Iterable[str]`` or ``Sequence[str]`` is expected. Note that even
37+
though they are similar to abstract base classes defined in
38+
:py:mod:`collections.abc` (formerly ``collections``), they are not identical. In
39+
particular, prior to Python 3.9, the built-in collection type objects do not
40+
support indexing.

docs/source/cheat_sheet_py3.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Built-in types
6767
6868
# For tuples of fixed size, we specify the types of all the elements
6969
x: Tuple[int, str, float] = (3, "yes", 7.5)
70-
70+
7171
# For tuples of variable size, we use one type and ellipsis
7272
x: Tuple[int, ...] = (1, 2, 3)
7373
@@ -226,6 +226,8 @@ that are common in idiomatic Python are standardized.
226226
f({3: 'yes', 4: 'no'})
227227
228228
229+
You can even make your own duck types using :ref:`protocol-types`.
230+
229231
Classes
230232
*******
231233

@@ -319,7 +321,7 @@ Decorators
319321
**********
320322

321323
Decorator functions can be expressed via generics. See
322-
:ref:`declaring-decorators` for the more details.
324+
:ref:`declaring-decorators` for more details.
323325

324326
.. code-block:: python
325327

docs/source/duck_type_compatibility.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ supported for a small set of built-in types:
88

99
* ``int`` is duck type compatible with ``float`` and ``complex``.
1010
* ``float`` is duck type compatible with ``complex``.
11+
* ``bytearray`` and ``memoryview`` are duck type compatible with ``bytes``.
1112
* In Python 2, ``str`` is duck type compatible with ``unicode``.
1213

1314
For example, mypy considers an ``int`` object to be valid whenever a

docs/source/existing_code.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ A simple CI script could look something like this:
114114

115115
.. code-block:: text
116116
117-
python3 -m pip install mypy==0.600 # Pinned version avoids surprises
118-
scripts/mypy # Runs with the correct options
117+
python3 -m pip install mypy==0.790 # Pinned version avoids surprises
118+
scripts/mypy # Run the mypy runner script you set up
119119
120120
Annotate widely imported modules
121121
--------------------------------
@@ -168,12 +168,11 @@ for further speedups.
168168
Introduce stricter options
169169
--------------------------
170170

171-
Mypy is very configurable. Once you get started with static typing,
172-
you may want to explore the various
173-
strictness options mypy provides to
174-
catch more bugs. For example, you can ask mypy to require annotations
175-
for all functions in certain modules to avoid accidentally introducing
176-
code that won't be type checked. Refer to :ref:`command-line` for the
177-
details.
171+
Mypy is very configurable. Once you get started with static typing, you may want
172+
to explore the various strictness options mypy provides to catch more bugs. For
173+
example, you can ask mypy to require annotations for all functions in certain
174+
modules to avoid accidentally introducing code that won't be type checked using
175+
:confval:`disallow_untyped_defs`, or type check code without annotations as well
176+
with :confval:`check_untyped_defs`. Refer to :ref:`config-file` for the details.
178177

179178
.. _PyAnnotate: https://github.com/dropbox/pyannotate

docs/source/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ Mypy is a static type checker for Python 3 and Python 2.7.
6969
error_codes
7070
error_code_list
7171
error_code_list2
72-
python36
7372
additional_features
7473
faq
7574

docs/source/introduction.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ annotations are just hints for mypy and don't interfere when running your progra
88
You run your program with a standard Python interpreter, and the annotations
99
are treated effectively as comments.
1010

11-
Using the Python 3 function annotation syntax (using the :pep:`484` notation) or
12-
a comment-based annotation syntax for Python 2 code, you will be able to
13-
efficiently annotate your code and use mypy to check the code for common
14-
errors. Mypy has a powerful and easy-to-use type system with modern features
15-
such as type inference, generics, callable types, tuple types,
16-
union types, and structural subtyping.
11+
Using the Python 3 annotation syntax (using :pep:`484` and :pep:`526` notation)
12+
or a comment-based annotation syntax for Python 2 code, you will be able to
13+
efficiently annotate your code and use mypy to check the code for common errors.
14+
Mypy has a powerful and easy-to-use type system with modern features such as
15+
type inference, generics, callable types, tuple types, union types, and
16+
structural subtyping.
1717

1818
As a developer, you decide how to use mypy in your workflow. You can always
1919
escape to dynamic typing as mypy's approach to static typing doesn't restrict

docs/source/python36.rst

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/source/stubs.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ code that uses the library. If you write a stub for a library module,
4141
consider making it available for other programmers that use mypy
4242
by contributing it back to the typeshed repo.
4343

44-
There is more information about creating stubs in the
45-
`mypy wiki <https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules>`_.
4644
The following sections explain the kinds of type annotations you can use
4745
in your programs and stub files.
4846

docs/source/type_inference_and_annotations.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,17 @@ must give each variable a type separately:
182182

183183
.. code-block:: python
184184
185-
i, found = 0, False # type: int, bool
185+
i, found = 0, False # type: int, bool
186186
187187
You can optionally use parentheses around the types, assignment targets
188188
and assigned expression:
189189

190190
.. code-block:: python
191191
192-
i, found = 0, False # type: (int, bool) # OK
193-
(i, found) = 0, False # type: int, bool # OK
194-
i, found = (0, False) # type: int, bool # OK
195-
(i, found) = (0, False) # type: (int, bool) # OK
192+
i, found = 0, False # type: (int, bool) # OK
193+
(i, found) = 0, False # type: int, bool # OK
194+
i, found = (0, False) # type: int, bool # OK
195+
(i, found) = (0, False) # type: (int, bool) # OK
196196
197197
Starred expressions
198198
*******************

0 commit comments

Comments
 (0)