1MYPY(1) User Commands MYPY(1)
2
3
4
6 mypy - manual page for mypy 0.782-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 - http://mypy.readthedocs.io/en/latest/getting_started.html
23
24 For more details on both running mypy and using the flags below, see:
25
26 - http://mypy.readthedocs.io/en/latest/running_mypy.html -
27 http://mypy.readthedocs.io/en/latest/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 - http://mypy.readthedocs.io/en/latest/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
47 options per each module.
48
49 --config-file CONFIG_FILE
50 Configuration file, must have a [mypy] section (defaults to
51 mypy.ini, .mypy.ini, setup.cfg, ~/.config/mypy/config,
52 ~/.mypy.ini)
53
54 --warn-unused-configs
55 Warn about unused '[mypy-<pattern>]' config sections (inverse:
56 --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
84 using 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
95 (defaults 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
139 incomplete 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
151 (inverse: --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 http://mypy.readthedocs.io/en/lat‐
157 est/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 or redundant (inverse: --no-warnunreachable)
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
196 (inverse: --disallow-redefinition)
197
198 --no-implicit-reexport
199 Treat imports as private unless aliased (inverse:
200 --implicit-reexport)
201
202 --strict-equality
203 Prohibit equality, identity, and container checks for non-over‐
204 lapping types (inverse: --no-strictequality)
205
206 --strict
207 Strict mode; enables the following flags: --warnunused-configs,
208 --disallow-any-generics, --disallow-subclassing-any, --disal‐
209 low-untypedcalls, --disallow-untyped-defs, --disallowincom‐
210 plete-defs, --check-untyped-defs, --disallowuntyped-decorators,
211 --no-implicit-optional, --warn-redundant-casts,
212 --warn-unused-ignores, --warn-return-any, --no-implicit-reex‐
213 port, --strict-equality
214
215 Configuring error messages:
216 Adjust the amount of detail shown in error messages.
217
218 --show-error-context
219 Precede errors with "note:" messages explaining context
220 (inverse: --hide-error-context)
221
222 --show-column-numbers
223 Show column numbers in error messages (inverse: --hide-col‐
224 umn-numbers)
225
226 --show-error-codes
227 Show error codes in error messages (inverse: --hide-error-codes)
228
229 --pretty
230 Use visually nicer output in error messages: Use soft word wrap,
231 show source code snippets, and show error location markers
232 (inverse: --no-pretty)
233
234 --no-color-output
235 Do not colorize error messages (inverse: --coloroutput)
236
237 --no-error-summary
238 Do not show error stats summary (inverse: --errorsummary)
239
240 --show-absolute-path
241 Show absolute paths to files (inverse: --hideabsolute-path)
242
243 Incremental mode:
244 Adjust how mypy incrementally type checks and caches modules.
245 Mypy caches type information about modules into a cache to let
246 you speed up future invocations of mypy. Also see mypy's daemon
247 mode: mypy.readthedocs.io/en/latest/mypy_daemon.html#mypy-daemon
248
249 --no-incremental
250 Disable module cache (inverse: --incremental)
251
252 --cache-dir DIR
253 Store module cache info in the given folder in incremental mode
254 (defaults to '.mypy_cache')
255
256 --sqlite-cache
257 Use a sqlite database to store the cache (inverse:
258 --no-sqlite-cache)
259
260 --cache-fine-grained
261 Include fine-grained dependency information in the cache for the
262 mypy daemon
263
264 --skip-version-check
265 Allow using cache written by older mypy version
266
267 --skip-cache-mtime-checks
268 Skip cache internal consistency checks based on mtime
269
270 Advanced options:
271 Debug and customize mypy internals.
272
273 --pdb Invoke pdb on fatal error
274
275 --show-traceback, --tb
276 Show traceback on fatal error
277
278 --raise-exceptions
279 Raise exception on fatal error
280
281 --custom-typing-module MODULE
282 Use a custom typing module
283
284 --custom-typeshed-dir DIR
285 Use the custom typeshed in DIR
286
287 --warn-incomplete-stub
288 Warn if missing type annotation in typeshed, only relevant with
289 --disallow-untyped-defs or --disallow-incomplete-defs enabled
290 (inverse: --nowarn-incomplete-stub)
291
292 --shadow-file SOURCE_FILE SHADOW_FILE
293 When encountering SOURCE_FILE, read and type check the contents
294 of SHADOW_FILE instead.
295
296 Report generation:
297 Generate a report in the specified format.
298
299 --any-exprs-report DIR
300
301 --cobertura-xml-report DIR
302
303 --html-report DIR
304
305 --linecount-report DIR
306
307 --linecoverage-report DIR
308
309 --lineprecision-report DIR
310
311 --txt-report DIR
312
313 --xml-report DIR
314
315 --xslt-html-report DIR
316
317 --xslt-txt-report DIR
318
319 Miscellaneous:
320 --junit-xml JUNIT_XML
321 Write junit.xml to the given file
322
323 --find-occurrences CLASS.MEMBER
324 Print out all usages of a class member (experimental)
325
326 --scripts-are-modules
327 Script x becomes module x instead of __main__
328
329 Running code:
330 Specify the code you want to type check. For more details, see
331 mypy.readthedocs.io/en/latest/running_mypy.html#running-mypy
332
333 -m MODULE, --module MODULE
334 Type-check module; can repeat for more modules
335
336 -p PACKAGE, --package PACKAGE
337 Type-check package recursively; can be repeated
338
339 -c PROGRAM_TEXT, --command PROGRAM_TEXT
340 Type-check program passed in as string
341
342 files Type-check given files or directories
343
344 Environment variables:
345 Define MYPYPATH for additional module search path entries.
346 Define MYPY_CACHE_DIR to override configuration cache_dir path.
347
348
349
350mypy 0.782-dev July 2020 MYPY(1)