@@ -9,9 +9,10 @@ of the previous sections.
9
9
Dataclasses
10
10
***********
11
11
12
- In Python 3.7, a new `` dataclasses ` ` module has been added to the standard library.
12
+ In Python 3.7, a new :py:mod: ` dataclasses ` module has been added to the standard library.
13
13
This module allows defining and customizing simple boilerplate-free classes.
14
- They can be defined using the ``@dataclasses.dataclass `` decorator:
14
+ They can be defined using the :py:func: `@dataclasses.dataclass
15
+ <python:dataclasses.dataclass> ` decorator:
15
16
16
17
.. code-block :: python
17
18
@@ -25,7 +26,7 @@ They can be defined using the ``@dataclasses.dataclass`` decorator:
25
26
test = Application(" Testing..." ) # OK
26
27
bad = Application(" Testing..." , " with plugin" ) # Error: List[str] expected
27
28
28
- Mypy will detect special methods (such as `` __lt__ ` `) depending on the flags used to
29
+ Mypy will detect special methods (such as :py:meth: ` __lt__ <object.__lt__> `) depending on the flags used to
29
30
define dataclasses. For example:
30
31
31
32
.. code-block :: python
@@ -65,16 +66,16 @@ class can be used:
65
66
66
67
val = unbox(BoxedData(42 , " <important>" )) # OK, inferred type is int
67
68
68
- For more information see `official docs <https://docs. python.org/3/ library/dataclasses.html >`_
69
- and ` PEP 557 < https://www.python.org/dev/peps/ pep-0557/ >`_ .
69
+ For more information see :doc: `official docs <python: library/dataclasses >`
70
+ and : pep: ` 557 ` .
70
71
71
72
Caveats/Known Issues
72
73
====================
73
74
74
- Some functions in the `` dataclasses `` module, such as `` replace() `` and `` asdict() ` `,
75
+ Some functions in the :py:mod: ` dataclasses ` module, such as :py:func: ` ~dataclasses. replace` and :py:func: ` ~dataclasses. asdict `,
75
76
have imprecise (too permissive) types. This will be fixed in future releases.
76
77
77
- Mypy does not yet recognize aliases of `` dataclasses.dataclass ` `, and will
78
+ Mypy does not yet recognize aliases of :py:func: ` dataclasses.dataclass <dataclasses.dataclass> `, and will
78
79
probably never recognize dynamically computed decorators. The following examples
79
80
do **not ** work:
80
81
@@ -110,7 +111,7 @@ do **not** work:
110
111
The attrs package
111
112
*****************
112
113
113
- `attrs <http://www. attrs.org/en/stable >`_ is a package that lets you define
114
+ :doc: `attrs <attrs:index >` is a package that lets you define
114
115
classes without writing boilerplate code. Mypy can detect uses of the
115
116
package and will generate the necessary method definitions for decorated
116
117
classes using the type annotations it finds.
@@ -139,7 +140,7 @@ If you're using ``auto_attribs=True`` you must use variable annotations.
139
140
three: int = attr.ib(8 )
140
141
141
142
Typeshed has a couple of "white lie" annotations to make type checking
142
- easier. `` attr.ib `` and `` attr.Factory ` ` actually return objects, but the
143
+ easier. :py:func: ` attr.ib ` and :py:class: ` attr.Factory ` actually return objects, but the
143
144
annotation says these return the types that they expect to be assigned to.
144
145
That enables this to work:
145
146
@@ -174,9 +175,9 @@ Caveats/Known Issues
174
175
175
176
* Currently, ``converter `` only supports named functions. If mypy finds something else it
176
177
will complain about not understanding the argument and the type annotation in
177
- `` __init__ ` ` will be replaced by ``Any ``.
178
+ :py:meth: ` __init__ <object.__init__> ` will be replaced by ``Any ``.
178
179
179
- * `Validator decorators <http://www. attrs.org/en/stable/examples.html#validators >`_
180
+ * :ref: `Validator decorators <attrs:examples_validators >`
180
181
and `default decorators <http://www.attrs.org/en/stable/examples.html#defaults >`_
181
182
are not type-checked against the attribute they are setting/validating.
182
183
@@ -285,7 +286,7 @@ run after starting or restarting the daemon.
285
286
286
287
The mypy daemon requires extra fine-grained dependency data in
287
288
the cache files which aren't included by default. To use caching with
288
- the mypy daemon, use the `` --cache-fine-grained ` ` option in your CI
289
+ the mypy daemon, use the :option: ` --cache-fine-grained <mypy --cache-fine-grained> ` option in your CI
289
290
build::
290
291
291
292
$ mypy --cache-fine-grained <args...>
@@ -325,7 +326,7 @@ at least if your codebase is hundreds of thousands of lines or more:
325
326
network), the script can still fall back to a normal incremental build.
326
327
327
328
* You can have multiple local cache directories for different local branches
328
- using the `` --cache-dir ` ` option. If the user switches to an existing
329
+ using the :option: ` --cache-dir <mypy --cache-dir> ` option. If the user switches to an existing
329
330
branch where downloaded cache data is already available, you can continue
330
331
to use the existing cache data instead of redownloading the data.
331
332
@@ -347,16 +348,16 @@ Extended Callable types
347
348
This feature is deprecated. You can use
348
349
:ref: `callback protocols <callback_protocols >` as a replacement.
349
350
350
- As an experimental mypy extension, you can specify `` Callable ` ` types
351
+ As an experimental mypy extension, you can specify :py:data: ` ~typing. Callable ` types
351
352
that support keyword arguments, optional arguments, and more. When
352
- you specify the arguments of a Callable, you can choose to supply just
353
+ you specify the arguments of a :py:data: ` ~typing. Callable` , you can choose to supply just
353
354
the type of a nameless positional argument, or an "argument specifier"
354
355
representing a more complicated form of argument. This allows one to
355
356
more closely emulate the full range of possibilities given by the
356
357
``def `` statement in Python.
357
358
358
359
As an example, here's a complicated function definition and the
359
- corresponding `` Callable ` `:
360
+ corresponding :py:data: ` ~typing. Callable `:
360
361
361
362
.. code-block :: python
362
363
@@ -433,7 +434,7 @@ purpose:
433
434
In all cases, the ``type `` argument defaults to ``Any ``, and if the
434
435
``name `` argument is omitted the argument has no name (the name is
435
436
required for ``NamedArg `` and ``DefaultNamedArg ``). A basic
436
- `` Callable ` ` such as
437
+ :py:data: ` ~typing. Callable ` such as
437
438
438
439
.. code-block :: python
439
440
@@ -445,7 +446,7 @@ is equivalent to the following:
445
446
446
447
MyFunc = Callable[[Arg(int ), Arg(str ), Arg(int )], float ]
447
448
448
- A `` Callable ` ` with unspecified argument types, such as
449
+ A :py:data: ` ~typing. Callable ` with unspecified argument types, such as
449
450
450
451
.. code-block :: python
451
452
0 commit comments