@@ -277,6 +277,25 @@ If you are getting this error, try to obtain type hints for the library you're u
277
277
to the library -- see our documentation on creating
278
278
:ref: `PEP 561 compliant packages <installed-packages >`.
279
279
280
+ 4. Force mypy to analyze the library as best as it can (as if the library provided
281
+ a ``py.typed `` file), despite it likely missing any type annotations. In general,
282
+ the quality of type checking will be poor and mypy may have issues when
283
+ analyzing code not designed to be type checked.
284
+
285
+ You can do this via setting the
286
+ :option: `--follow-untyped-imports <mypy --follow-untyped-imports> `
287
+ command line flag or :confval: `follow_untyped_imports ` config file option to True.
288
+ This option can be specified on a per-module basis as well::
289
+
290
+ # mypy.ini
291
+ [mypy-untyped_package.*]
292
+ follow_untyped_imports = True
293
+
294
+ # pyproject.toml
295
+ [[tool.mypy.overrides]]
296
+ module = ["untyped_package.*"]
297
+ follow_untyped_imports = true
298
+
280
299
If you are unable to find any existing type hints nor have time to write your
281
300
own, you can instead *suppress * the errors.
282
301
@@ -295,9 +314,15 @@ not catch errors in its use.
295
314
all import errors associated with that library and that library alone by
296
315
adding the following section to your config file::
297
316
317
+ # mypy.ini
298
318
[mypy-foobar.*]
299
319
ignore_missing_imports = True
300
320
321
+ # pyproject.toml
322
+ [[tool.mypy.overrides]]
323
+ module = ["foobar.*"]
324
+ ignore_missing_imports = true
325
+
301
326
Note: this option is equivalent to adding a ``# type: ignore `` to every
302
327
import of ``foobar `` in your codebase. For more information, see the
303
328
documentation about configuring
@@ -311,22 +336,20 @@ not catch errors in its use.
311
336
312
337
You can also set :confval: `disable_error_code `, like so::
313
338
339
+ # mypy.ini
314
340
[mypy]
315
341
disable_error_code = import-untyped
316
342
343
+ # pyproject.toml
344
+ [tool.mypy]
345
+ disable_error_code = ["import-untyped"]
317
346
318
347
You can also set the :option: `--ignore-missing-imports <mypy --ignore-missing-imports> `
319
348
command line flag or set the :confval: `ignore_missing_imports ` config file
320
349
option to True in the *global * section of your mypy config file. We
321
350
recommend avoiding ``--ignore-missing-imports `` if possible: it's equivalent
322
351
to adding a ``# type: ignore `` to all unresolved imports in your codebase.
323
352
324
- 4. To make mypy typecheck imports from modules without stubs or a py.typed
325
- marker, you can set the :option: `--follow-untyped-imports <mypy --follow-untyped-imports> `
326
- command line flag or set the :confval: `follow_untyped_imports ` config file option to True,
327
- either in the global section of your mypy config file, or individually on a
328
- per-module basis.
329
-
330
353
331
354
Library stubs not installed
332
355
---------------------------
0 commit comments