@@ -15,7 +15,7 @@ and recommendations on how to handle any issues you may encounter
15
15
along the way.
16
16
17
17
If you are interested in learning about how to configure the
18
- actual way mypy type checks your code, see our
18
+ actual way mypy type checks your code, see our
19
19
:ref: `command-line ` guide.
20
20
21
21
@@ -51,7 +51,7 @@ different ways.
51
51
52
52
Mypy will use an algorithm very similar to the one Python uses to
53
53
find where modules and imports are located on the file system.
54
- For more details, see :ref: `finding-imports `.
54
+ For more details, see :ref: `finding-imports `.
55
55
56
56
3. Third, you can use the ``-p `` (long form: ``--package ``) flag to
57
57
specify a package to be (recursively) type checked. This flag
@@ -97,16 +97,16 @@ you can use this instead::
97
97
98
98
This file can technically also contain any command line flag, not
99
99
just file paths. However, if you want to configure many different
100
- flags, the recommended approach is to use a
100
+ flags, the recommended approach is to use a
101
101
:ref: `configuration file <config-file >` instead.
102
102
103
103
104
104
105
105
How mypy handles imports
106
106
************************
107
107
108
- When mypy encounters an ``import `` statement, it will first
109
- :ref: `attempt to locate <finding-imports >` that module
108
+ When mypy encounters an ``import `` statement, it will first
109
+ :ref: `attempt to locate <finding-imports >` that module
110
110
or type stubs for that module in the file system. Mypy will then
111
111
type check the imported module. There are three different outcomes
112
112
of this process:
@@ -173,9 +173,9 @@ are trying to use has done neither of these things. In that case, you can try:
173
173
174
174
2. :ref: `Writing your own stub files <stub-files >` containing type hints for
175
175
the library. You can point mypy at your type hints either by passing
176
- them in via the command line, by adding the location to the
177
- `MYPYPATH ` environment variable, or by using the ``mypy_path ``
178
- :ref: `config file option <config-file-import-discovery-global >`.
176
+ them in via the command line, by adding the location to the
177
+ `` MYPYPATH `` environment variable, or by using the ``mypy_path ``
178
+ :ref: `config file option <config-file-import-discovery-global >`.
179
179
180
180
Note that if you decide to write your own stub files, they don't need
181
181
to be complete! A good strategy is to add stubs for just the parts
@@ -188,7 +188,7 @@ are trying to use has done neither of these things. In that case, you can try:
188
188
If the module is a third party library, but you cannot find any existing
189
189
type hints nor have time to write your own, you can *silence * the errors:
190
190
191
- 1. To silence a *single * missing import error, add a `# type: ignore ` at the end of the
191
+ 1. To silence a *single * missing import error, add a `` # type: ignore ` ` at the end of the
192
192
line containing the import.
193
193
194
194
2. To silence *all * missing import imports errors from a single library, add
@@ -233,7 +233,7 @@ If the module is a part of the standard library, try:
233
233
errors. After upgrading, we recommend running mypy using the
234
234
``--warn-unused-ignores `` flag to help you find any ``# type: ignore ``
235
235
annotations you no longer need.
236
-
236
+
237
237
.. _follow-imports :
238
238
239
239
Following imports
@@ -243,15 +243,15 @@ Mypy is designed to :ref:`doggedly follow all imports <finding-imports>`,
243
243
even if the imported module is not a file you explicitly wanted mypy to check.
244
244
245
245
For example, suppose we have two modules ``mycode.foo `` and ``mycode.bar ``:
246
- the former has type hints and the latter does not. We run
246
+ the former has type hints and the latter does not. We run
247
247
``mypy -m mycode.foo `` and mypy discovers that ``mycode.foo `` imports
248
248
``mycode.bar ``.
249
249
250
250
How do we want mypy to type check ``mycode.bar ``? We can configure the
251
251
desired behavior by using the ``--follow-imports `` flag. This flag
252
252
accepts one of four string values:
253
253
254
- - ``normal `` (the default) follows all imports normally and
254
+ - ``normal `` (the default) follows all imports normally and
255
255
type checks all top level code (as well as the bodies of all
256
256
functions and methods with at least one type annotation in
257
257
the signature).
@@ -330,12 +330,12 @@ to modules to type check.
330
330
One more thing about checking modules and packages: if the directory
331
331
*containing * a module or package specified on the command line has an
332
332
``__init__.py[i] `` file, mypy assigns these an absolute module name by
333
- crawling up the path until no ``__init__.py[i] `` file is found.
333
+ crawling up the path until no ``__init__.py[i] `` file is found.
334
334
335
335
For example, suppose we run the command ``mypy foo/bar/baz.py `` where
336
336
``foo/bar/__init__.py `` exists but ``foo/__init__.py `` does not. Then
337
337
the module name assumed is ``bar.baz `` and the directory ``foo `` is
338
- added to mypy's module search path.
338
+ added to mypy's module search path.
339
339
340
340
On the other hand, if ``foo/bar/__init__.py `` did not exist, ``foo/bar ``
341
341
would be added to the module search path instead, and the module name
0 commit comments