1MYPY(1) User Commands MYPY(1)
2
3
4
6 mypy - manual page for mypy 0.982-dev
7
9 usage: mypy [-h] [-v] [-V] [more options; see below]
10
11 [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
12
13 Mypy is a program that will type check your Python code.
14
15 Pass in any files or folders you want to type check. Mypy will recur‐
16 sively traverse any provided folders to find .py files:
17
18 $ mypy my_program.py my_src_folder
19
20 For more information on getting started, see:
21
22 - https://mypy.readthedocs.io/en/stable/getting_started.html
23
24 For more details on both running mypy and using the flags below, see:
25
26 - https://mypy.readthedocs.io/en/stable/running_mypy.html -
27 https://mypy.readthedocs.io/en/stable/command_line.html
28
29 You can also use a config file to configure mypy instead of using com‐
30 mand line flags. For more details, see:
31
32 - https://mypy.readthedocs.io/en/stable/config_file.html
33
34 Optional arguments:
35 -h, --help
36 Show this help message and exit
37
38 -v, --verbose
39 More verbose messages
40
41 -V, --version
42 Show program's version number and exit
43
44 Config file:
45 Use a config file instead of command line arguments. This is
46 useful if you are using many flags or want to set different op‐
47 tions per each module.
48
49 --config-file CONFIG_FILE
50 Configuration file, must have a [mypy] section (defaults to
51 mypy.ini, .mypy.ini, pyproject.toml, setup.cfg, ~/.con‐
52 fig/mypy/config, ~/.mypy.ini)
53
54 --warn-unused-configs
55 Warn about unused '[mypy-<pattern>]' or '[[tool.mypy.over‐
56 rides]]' config sections (inverse: --no-warn-unused-configs)
57
58 Import discovery:
59 Configure how imports are discovered and followed.
60
61 --namespace-packages
62 Support namespace packages (PEP 420, __init__.pyless) (inverse:
63 --no-namespace-packages)
64
65 --ignore-missing-imports
66 Silently ignore imports of missing modules
67
68 --follow-imports {normal,silent,skip,error}
69 How to treat imports (default normal)
70
71 --python-executable EXECUTABLE
72 Python executable used for finding PEP 561 compliant installed
73 packages and stubs
74
75 --no-site-packages
76 Do not search for installed PEP 561 compliant packages
77
78 --no-silence-site-packages
79 Do not silence errors in PEP 561 compliant installed packages
80
81 Platform configuration:
82 Type check code assuming it will be run under certain runtime
83 conditions. By default, mypy assumes your code will be run us‐
84 ing the same operating system and Python version you are using
85 to run mypy itself.
86
87 --python-version x.y
88 Type check code assuming it will be running on Python x.y
89
90 -2, --py2
91 Use Python 2 mode (same as --python-version 2.7)
92
93 --platform PLATFORM
94 Type check special-cased code for the given OS platform (de‐
95 faults to sys.platform)
96
97 --always-true NAME
98 Additional variable to be considered True (may be repeated)
99
100 --always-false NAME
101 Additional variable to be considered False (may be repeated)
102
103 Disallow dynamic typing:
104 Disallow the use of the dynamic 'Any' type under certain condi‐
105 tions.
106
107 --disallow-any-unimported
108 Disallow Any types resulting from unfollowed imports
109
110 --disallow-any-expr
111 Disallow all expressions that have type Any
112
113 --disallow-any-decorated
114 Disallow functions that have Any in their signature after deco‐
115 rator transformation
116
117 --disallow-any-explicit
118 Disallow explicit Any in type positions
119
120 --disallow-any-generics
121 Disallow usage of generic types that do not specify explicit
122 type parameters (inverse: --allow-any-generics)
123
124 --disallow-subclassing-any
125 Disallow subclassing values of type 'Any' when defining classes
126 (inverse: --allow-subclassingany)
127
128 Untyped definitions and calls:
129 Configure how untyped definitions and calls are handled. Note:
130 by default, mypy ignores any untyped function definitions and
131 assumes any calls to such functions have a return type of 'Any'.
132
133 --disallow-untyped-calls
134 Disallow calling functions without type annotations from func‐
135 tions with type annotations (inverse: --allow-untyped-calls)
136
137 --disallow-untyped-defs
138 Disallow defining functions without type annotations or with in‐
139 complete type annotations (inverse: --allow-untyped-defs)
140
141 --disallow-incomplete-defs
142 Disallow defining functions with incomplete type annotations
143 (inverse: --allow-incomplete-defs)
144
145 --check-untyped-defs
146 Type check the interior of functions without type annotations
147 (inverse: --no-check-untyped-defs)
148
149 --disallow-untyped-decorators
150 Disallow decorating typed functions with untyped decorators (in‐
151 verse: --allow-untyped-decorators)
152
153 None and Optional handling:
154 Adjust how values of type 'None' are handled. For more context
155 on how mypy handles values of type 'None', see:
156 https://mypy.readthedocs.io/en/sta‐
157 ble/kinds_of_types.html#no-strictoptional
158
159 --no-implicit-optional
160 Don't assume arguments with default values of None are Optional
161 (inverse: --implicit-optional)
162
163 --no-strict-optional
164 Disable strict Optional checks (inverse: --strictoptional)
165
166 Configuring warnings:
167 Detect code that is sound but redundant or problematic.
168
169 --warn-redundant-casts
170 Warn about casting an expression to its inferred type (inverse:
171 --no-warn-redundant-casts)
172
173 --warn-unused-ignores
174 Warn about unneeded '# type: ignore' comments (inverse:
175 --no-warn-unused-ignores)
176
177 --no-warn-no-return
178 Do not warn about functions that end without returning (inverse:
179 --warn-no-return)
180
181 --warn-return-any
182 Warn about returning values of type Any from nonAny typed func‐
183 tions (inverse: --no-warn-returnany)
184
185 --warn-unreachable
186 Warn about statements or expressions inferred to be unreachable
187 (inverse: --no-warn-unreachable)
188
189 Miscellaneous strictness flags:
190 --allow-untyped-globals
191 Suppress toplevel errors caused by missing annotations (inverse:
192 --disallow-untyped-globals)
193
194 --allow-redefinition
195 Allow unconditional variable redefinition with a new type (in‐
196 verse: --disallow-redefinition)
197
198 --no-implicit-reexport
199 Treat imports as private unless aliased (inverse: --implicit-re‐
200 export)
201
202 --strict-equality
203 Prohibit equality, identity, and container checks for non-over‐
204 lapping types (inverse: --no-strictequality)
205
206 --strict-concatenate
207 Make arguments prepended via Concatenate be truly posi‐
208 tional-only (inverse: --no-strict-concatenate)
209
210 --strict
211 Strict mode; enables the following flags: --warnunused-configs,
212 --disallow-any-generics, --disallow-subclassing-any, --disal‐
213 low-untypedcalls, --disallow-untyped-defs, --disallowincom‐
214 plete-defs, --check-untyped-defs, --disallowuntyped-decorators,
215 --no-implicit-optional, --warn-redundant-casts, --warn-un‐
216 used-ignores, --warn-return-any, --no-implicit-reexport,
217 --strict-equality, --strict-concatenate
218
219 --disable-error-code NAME
220 Disable a specific error code
221
222 --enable-error-code NAME
223 Enable a specific error code
224
225 Configuring error messages:
226 Adjust the amount of detail shown in error messages.
227
228 --show-error-context
229 Precede errors with "note:" messages explaining context (in‐
230 verse: --hide-error-context)
231
232 --show-column-numbers
233 Show column numbers in error messages (inverse: --hide-col‐
234 umn-numbers)
235
236 --show-error-end
237 Show end line/end column numbers in error messages. This implies
238 --show-column-numbers (inverse: --hide-error-end)
239
240 --show-error-codes
241 Show error codes in error messages (inverse: --hide-error-codes)
242
243 --pretty
244 Use visually nicer output in error messages: Use soft word wrap,
245 show source code snippets, and show error location markers (in‐
246 verse: --no-pretty)
247
248 --no-color-output
249 Do not colorize error messages (inverse: --coloroutput)
250
251 --no-error-summary
252 Do not show error stats summary (inverse: --errorsummary)
253
254 --show-absolute-path
255 Show absolute paths to files (inverse: --hideabsolute-path)
256
257 Incremental mode:
258 Adjust how mypy incrementally type checks and caches modules.
259 Mypy caches type information about modules into a cache to let
260 you speed up future invocations of mypy. Also see mypy's daemon
261 mode: mypy.readthedocs.io/en/stable/mypy_daemon.html#mypy-daemon
262
263 --no-incremental
264 Disable module cache (inverse: --incremental)
265
266 --cache-dir DIR
267 Store module cache info in the given folder in incremental mode
268 (defaults to '.mypy_cache')
269
270 --sqlite-cache
271 Use a sqlite database to store the cache (inverse:
272 --no-sqlite-cache)
273
274 --cache-fine-grained
275 Include fine-grained dependency information in the cache for the
276 mypy daemon
277
278 --skip-version-check
279 Allow using cache written by older mypy version
280
281 --skip-cache-mtime-checks
282 Skip cache internal consistency checks based on mtime
283
284 Advanced options:
285 Debug and customize mypy internals.
286
287 --pdb Invoke pdb on fatal error
288
289 --show-traceback, --tb
290 Show traceback on fatal error
291
292 --raise-exceptions
293 Raise exception on fatal error
294
295 --custom-typing-module MODULE
296 Use a custom typing module
297
298 --enable-recursive-aliases
299 Experimental support for recursive type aliases
300
301 --custom-typeshed-dir DIR
302 Use the custom typeshed in DIR
303
304 --warn-incomplete-stub
305 Warn if missing type annotation in typeshed, only relevant with
306 --disallow-untyped-defs or --disallow-incomplete-defs enabled
307 (inverse: --nowarn-incomplete-stub)
308
309 --shadow-file SOURCE_FILE SHADOW_FILE
310 When encountering SOURCE_FILE, read and type check the contents
311 of SHADOW_FILE instead.
312
313 Report generation:
314 Generate a report in the specified format.
315
316 --any-exprs-report DIR
317
318 --cobertura-xml-report DIR
319
320 --html-report DIR
321
322 --linecount-report DIR
323
324 --linecoverage-report DIR
325
326 --lineprecision-report DIR
327
328 --txt-report DIR
329
330 --xml-report DIR
331
332 --xslt-html-report DIR
333
334 --xslt-txt-report DIR
335
336 Miscellaneous:
337 --junit-xml JUNIT_XML
338 Write junit.xml to the given file
339
340 --find-occurrences CLASS.MEMBER
341 Print out all usages of a class member (experimental)
342
343 --scripts-are-modules
344 Script x becomes module x instead of __main__
345
346 --install-types
347 Install detected missing library stub packages using pip (in‐
348 verse: --no-install-types)
349
350 --non-interactive
351 Install stubs without asking for confirmation and hide errors,
352 with --install-types (inverse: --interactive)
353
354 Running code:
355 Specify the code you want to type check. For more details, see
356 mypy.readthedocs.io/en/stable/running_mypy.html#running-mypy
357
358 --explicit-package-bases
359 Use current directory and MYPYPATH to determine module names of
360 files passed (inverse: --noexplicit-package-bases)
361
362 --exclude PATTERN
363 Regular expression to match file names, directory names or paths
364 which mypy should ignore while recursively discovering files to
365 check, e.g. --exclude '/setup\.py$'. May be specified more than
366 once, eg. --exclude a --exclude b
367
368 -m MODULE, --module MODULE
369 Type-check module; can repeat for more modules
370
371 -p PACKAGE, --package PACKAGE
372 Type-check package recursively; can be repeated
373
374 -c PROGRAM_TEXT, --command PROGRAM_TEXT
375 Type-check program passed in as string
376
377 files Type-check given files or directories
378
379 Environment variables:
380 Define MYPYPATH for additional module search path entries. De‐
381 fine MYPY_CACHE_DIR to override configuration cache_dir path.
382
383
384
385mypy 0.982-dev October 2022 MYPY(1)