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