duty 1.2.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
duty/tools/_mypy.py ADDED
@@ -0,0 +1,502 @@
1
+ """Callable for [Mypy](https://github.com/python/mypy)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Literal
6
+
7
+ from duty.tools._base import LazyStderr, LazyStdout, Tool
8
+
9
+
10
+ class mypy(Tool): # noqa: N801
11
+ """Call [Mypy](https://github.com/python/mypy)."""
12
+
13
+ cli_name = "mypy"
14
+
15
+ def __init__(
16
+ self,
17
+ *paths: str,
18
+ config_file: str | None = None,
19
+ enable_incomplete_feature: bool | None = None,
20
+ verbose: bool | None = None,
21
+ warn_unused_configs: bool | None = None,
22
+ no_namespace_packages: bool | None = None,
23
+ ignore_missing_imports: bool | None = None,
24
+ follow_imports: Literal["normal", "silent", "skip", "error"] | None = None,
25
+ python_executable: str | None = None,
26
+ no_site_packages: bool | None = None,
27
+ no_silence_site_packages: bool | None = None,
28
+ python_version: str | None = None,
29
+ py2: bool | None = None,
30
+ platform: str | None = None,
31
+ always_true: list[str] | None = None,
32
+ always_false: list[str] | None = None,
33
+ disallow_any_unimported: bool | None = None,
34
+ disallow_any_expr: bool | None = None,
35
+ disallow_any_decorated: bool | None = None,
36
+ disallow_any_explicit: bool | None = None,
37
+ disallow_any_generics: bool | None = None,
38
+ disallow_subclassing_any: bool | None = None,
39
+ disallow_untyped_calls: bool | None = None,
40
+ disallow_untyped_defs: bool | None = None,
41
+ disallow_incomplete_defs: bool | None = None,
42
+ check_untyped_defs: bool | None = None,
43
+ disallow_untyped_decorators: bool | None = None,
44
+ implicit_optional: bool | None = None,
45
+ no_strict_optional: bool | None = None,
46
+ warn_redundant_casts: bool | None = None,
47
+ warn_unused_ignores: bool | None = None,
48
+ no_warn_no_return: bool | None = None,
49
+ warn_return_any: bool | None = None,
50
+ warn_unreachable: bool | None = None,
51
+ allow_untyped_globals: bool | None = None,
52
+ allow_redefinition: bool | None = None,
53
+ no_implicit_reexport: bool | None = None,
54
+ strict_equality: bool | None = None,
55
+ strict_concatenate: bool | None = None,
56
+ strict: bool | None = None,
57
+ disable_error_code: str | None = None,
58
+ enable_error_code: str | None = None,
59
+ show_error_context: bool | None = None,
60
+ show_column_numbers: bool | None = None,
61
+ show_error_end: bool | None = None,
62
+ hide_error_codes: bool | None = None,
63
+ pretty: bool | None = None,
64
+ no_color_output: bool | None = None,
65
+ no_error_summary: bool | None = None,
66
+ show_absolute_path: bool | None = None,
67
+ no_incremental: bool | None = None,
68
+ cache_dir: str | None = None,
69
+ sqlite_cache: bool | None = None,
70
+ cache_fine_grained: bool | None = None,
71
+ skip_version_check: bool | None = None,
72
+ skip_cache_mtime_checks: bool | None = None,
73
+ pdb: bool | None = None,
74
+ show_traceback: bool | None = None,
75
+ raise_exceptions: bool | None = None,
76
+ custom_typing_module: str | None = None,
77
+ disable_recursive_aliases: bool | None = None,
78
+ custom_typeshed_dir: str | None = None,
79
+ warn_incomplete_stub: bool | None = None,
80
+ shadow_file: tuple[str, str] | None = None,
81
+ any_exprs_report: str | None = None,
82
+ cobertura_xml_report: str | None = None,
83
+ html_report: str | None = None,
84
+ linecount_report: str | None = None,
85
+ linecoverage_report: str | None = None,
86
+ lineprecision_report: str | None = None,
87
+ txt_report: str | None = None,
88
+ xml_report: str | None = None,
89
+ xslt_html_report: str | None = None,
90
+ xslt_txt_report: str | None = None,
91
+ junit_xml: str | None = None,
92
+ find_occurrences: str | None = None,
93
+ scripts_are_modules: bool | None = None,
94
+ install_types: bool | None = None,
95
+ non_interactive: bool | None = None,
96
+ explicit_package_bases: bool | None = None,
97
+ exclude: str | None = None,
98
+ module: str | None = None,
99
+ package: str | None = None,
100
+ command: str | None = None,
101
+ ) -> None:
102
+ """Run mypy.
103
+
104
+ Parameters:
105
+ *paths: Path to scan.
106
+ config_file: Configuration file, must have a [mypy] section (defaults to mypy.ini, .mypy.ini,
107
+ enable_incomplete_feature: Enable support of incomplete/experimental features for early preview.
108
+ verbose: More verbose messages.
109
+ pyproject.toml, setup.cfg, /home/pawamoy/.config/mypy/config, ~/.config/mypy/config, ~/.mypy.ini).
110
+ warn_unused_configs: Warn about unused '[mypy-<pattern>]' or '[[tool.mypy.overrides]]' config sections
111
+ (inverse: --no-warn-unused-configs).
112
+ no_namespace_packages: Support namespace packages (PEP 420, __init__.py-less) (inverse: --namespace-packages).
113
+ ignore_missing_imports: Silently ignore imports of missing modules.
114
+ follow_imports: How to treat imports (default normal).
115
+ python_executable: Python executable used for finding PEP 561 compliant installed packages and stubs.
116
+ no_site_packages: Do not search for installed PEP 561 compliant packages.
117
+ no_silence_site_packages: Do not silence errors in PEP 561 compliant installed packages.
118
+ python_version: Type check code assuming it will be running on Python x.y.
119
+ py2: Use Python 2 mode (same as --python-version 2.7).
120
+ platform: Type check special-cased code for the given OS platform (defaults to sys.platform).
121
+ always_true: Additional variable to be considered True (may be repeated).
122
+ always_false: Additional variable to be considered False (may be repeated).
123
+ disallow_any_unimported: Disallow Any types resulting from unfollowed imports.
124
+ disallow_any_expr: Disallow all expressions that have type Any.
125
+ disallow_any_decorated: Disallow functions that have Any in their signature after decorator transformation.
126
+ disallow_any_explicit: Disallow explicit Any in type positions.
127
+ disallow_any_generics: Disallow usage of generic types that do not specify explicit type parameters
128
+ (inverse: --allow-any-generics).
129
+ disallow_subclassing_any: Disallow subclassing values of type 'Any' when defining classes
130
+ (inverse: --allow-subclassing-any).
131
+ disallow_untyped_calls: Disallow calling functions without type annotations from functions with type annotations
132
+ (inverse: --allow-untyped-calls).
133
+ disallow_untyped_defs: Disallow defining functions without type annotations or with incomplete type annotations
134
+ (inverse: --allow-untyped-defs).
135
+ disallow_incomplete_defs: Disallow defining functions with incomplete type annotations
136
+ (inverse: --allow-incomplete-defs).
137
+ check_untyped_defs: Type check the interior of functions without type annotations
138
+ (inverse: --no-check-untyped-defs).
139
+ disallow_untyped_decorators: Disallow decorating typed functions with untyped decorators
140
+ (inverse: --allow-untyped-decorators).
141
+ implicit_optional: Assume arguments with default values of None are Optional(inverse: --no-implicit-optional).
142
+ no_strict_optional: Disable strict Optional checks (inverse: --strict-optional).
143
+ warn_redundant_casts: Warn about casting an expression to its inferred type (inverse: --no-warn-redundant-casts).
144
+ warn_unused_ignores: Warn about unneeded '# type: ignore' comments (inverse: --no-warn-unused-ignores).
145
+ no_warn_no_return: Do not warn about functions that end without returning (inverse: --warn-no-return).
146
+ warn_return_any: Warn about returning values of type Any from non-Any typed functions (inverse: --no-warn-return-any).
147
+ warn_unreachable: Warn about statements or expressions inferred to be unreachable (inverse: --no-warn-unreachable).
148
+ allow_untyped_globals: Suppress toplevel errors caused by missing annotations (inverse: --disallow-untyped-globals).
149
+ allow_redefinition: Allow unconditional variable redefinition with a new type (inverse: --disallow-redefinition).
150
+ no_implicit_reexport: Treat imports as private unless aliased (inverse: --implicit-reexport).
151
+ strict_equality: Prohibit equality, identity, and container checks for non-overlapping types
152
+ (inverse: --no-strict-equality).
153
+ strict_concatenate: Make arguments prepended via Concatenate be truly positional-only (inverse: --no-strict-concatenate).
154
+ strict: Strict mode; enables the following flags: --warn-unused-configs, --disallow-any-generics,
155
+ --disallow-subclassing-any, --disallow-untyped-calls, --disallow-untyped-defs, --disallow-incomplete-defs,
156
+ --check-untyped-defs, --disallow-untyped-decorators, --warn-redundant-casts, --warn-unused-ignores,
157
+ --warn-return-any, --no-implicit-reexport, --strict-equality, --strict-concatenate.
158
+ disable_error_code: Disable a specific error code.
159
+ enable_error_code: Enable a specific error code.
160
+ show_error_context: Precede errors with "note:" messages explaining context (inverse: --hide-error-context).
161
+ show_column_numbers: Show column numbers in error messages (inverse: --hide-column-numbers).
162
+ show_error_end: Show end line/end column numbers in error messages. This implies --show-column-numbers
163
+ (inverse: --hide-error-end).
164
+ hide_error_codes: Hide error codes in error messages (inverse: --show-error-codes).
165
+ pretty: Use visually nicer output in error messages: Use soft word wrap, show source code snippets,
166
+ and show error location markers (inverse: --no-pretty).
167
+ no_color_output: Do not colorize error messages (inverse: --color-output).
168
+ no_error_summary: Do not show error stats summary (inverse: --error-summary).
169
+ show_absolute_path: Show absolute paths to files (inverse: --hide-absolute-path).
170
+ no_incremental: Disable module cache (inverse: --incremental).
171
+ cache_dir: Store module cache info in the given folder in incremental mode (defaults to '.mypy_cache').
172
+ sqlite_cache: Use a sqlite database to store the cache (inverse: --no-sqlite-cache).
173
+ cache_fine_grained: Include fine-grained dependency information in the cache for the mypy daemon.
174
+ skip_version_check: Allow using cache written by older mypy version.
175
+ skip_cache_mtime_checks: Skip cache internal consistency checks based on mtime.
176
+ pdb: Invoke pdb on fatal error.
177
+ show_traceback: Show traceback on fatal error.
178
+ raise_exceptions: Raise exception on fatal error.
179
+ custom_typing_module: Use a custom typing module.
180
+ disable_recursive_aliases: Disable experimental support for recursive type aliases.
181
+ custom_typeshed_dir: Use the custom typeshed in DIR.
182
+ warn_incomplete_stub: Warn if missing type annotation in typeshed, only relevant with --disallow-untyped-defs
183
+ or --disallow-incomplete-defs enabled (inverse: --no-warn-incomplete-stub).
184
+ shadow_file: When encountering SOURCE_FILE, read and type check the contents of SHADOW_FILE instead..
185
+ any_exprs_report: Report any expression.
186
+ cobertura_xml_report: Report Cobertura.
187
+ html_report: Report HTML.
188
+ linecount_report: Report line count.
189
+ linecoverage_report: Report line coverage.
190
+ lineprecision_report: Report line precision.
191
+ txt_report: Report text.
192
+ xml_report: Report XML.
193
+ xslt_html_report: Report XLST HTML.
194
+ xslt_txt_report: Report XLST text.
195
+ junit_xml: Write junit.xml to the given file.
196
+ find_occurrences: Print out all usages of a class member (experimental).
197
+ scripts_are_modules: Script x becomes module x instead of __main__.
198
+ install_types: Install detected missing library stub packages using pip (inverse: --no-install-types).
199
+ non_interactive: Install stubs without asking for confirmation and hide errors, with --install-types
200
+ (inverse: --interactive).
201
+ explicit_package_bases: Use current directory and MYPYPATH to determine module names of files passed
202
+ (inverse: --no-explicit-package-bases).
203
+ exclude: Regular expression to match file names, directory names or paths which mypy should ignore while
204
+ recursively discovering files to check, e.g. --exclude '/setup\\.py$'.
205
+ May be specified more than once, eg. --exclude a --exclude b.
206
+ module: Type-check module; can repeat for more modules.
207
+ package: Type-check package recursively; can be repeated.
208
+ command: Type-check program passed in as string.
209
+ """ # noqa: D301
210
+ cli_args = list(paths)
211
+
212
+ if enable_incomplete_feature:
213
+ cli_args.append("--enable-incomplete-feature")
214
+
215
+ if verbose:
216
+ cli_args.append("--verbose")
217
+
218
+ if config_file:
219
+ cli_args.append("--config-file")
220
+ cli_args.append(config_file)
221
+
222
+ if warn_unused_configs:
223
+ cli_args.append("--warn-unused-configs")
224
+
225
+ if no_namespace_packages:
226
+ cli_args.append("--no-namespace-packages")
227
+
228
+ if ignore_missing_imports:
229
+ cli_args.append("--ignore-missing-imports")
230
+
231
+ if follow_imports:
232
+ cli_args.append("--follow-imports")
233
+ cli_args.append(follow_imports)
234
+
235
+ if python_executable:
236
+ cli_args.append("--python-executable")
237
+ cli_args.append(python_executable)
238
+
239
+ if no_site_packages:
240
+ cli_args.append("--no-site-packages")
241
+
242
+ if no_silence_site_packages:
243
+ cli_args.append("--no-silence-site-packages")
244
+
245
+ if python_version:
246
+ cli_args.append("--python-version")
247
+ cli_args.append(python_version)
248
+
249
+ if py2:
250
+ cli_args.append("--py2")
251
+
252
+ if platform:
253
+ cli_args.append("--platform")
254
+ cli_args.append(platform)
255
+
256
+ if always_true:
257
+ for posarg in always_true:
258
+ cli_args.append("--always-true")
259
+ cli_args.append(posarg)
260
+
261
+ if always_false:
262
+ for posarg in always_false:
263
+ cli_args.append("--always-false")
264
+ cli_args.append(posarg)
265
+
266
+ if disallow_any_unimported:
267
+ cli_args.append("--disallow-any-unimported")
268
+
269
+ if disallow_any_expr:
270
+ cli_args.append("--disallow-any-expr")
271
+
272
+ if disallow_any_decorated:
273
+ cli_args.append("--disallow-any-decorated")
274
+
275
+ if disallow_any_explicit:
276
+ cli_args.append("--disallow-any-explicit")
277
+
278
+ if disallow_any_generics:
279
+ cli_args.append("--disallow-any-generics")
280
+
281
+ if disallow_subclassing_any:
282
+ cli_args.append("--disallow-subclassing-any")
283
+
284
+ if disallow_untyped_calls:
285
+ cli_args.append("--disallow-untyped-calls")
286
+
287
+ if disallow_untyped_defs:
288
+ cli_args.append("--disallow-untyped-defs")
289
+
290
+ if disallow_incomplete_defs:
291
+ cli_args.append("--disallow-incomplete-defs")
292
+
293
+ if check_untyped_defs:
294
+ cli_args.append("--check-untyped-defs")
295
+
296
+ if disallow_untyped_decorators:
297
+ cli_args.append("--disallow-untyped-decorators")
298
+
299
+ if implicit_optional:
300
+ cli_args.append("--implicit-optional")
301
+
302
+ if no_strict_optional:
303
+ cli_args.append("--no-strict-optional")
304
+
305
+ if warn_redundant_casts:
306
+ cli_args.append("--warn-redundant-casts")
307
+
308
+ if warn_unused_ignores:
309
+ cli_args.append("--warn-unused-ignores")
310
+
311
+ if no_warn_no_return:
312
+ cli_args.append("--no-warn-no-return")
313
+
314
+ if warn_return_any:
315
+ cli_args.append("--warn-return-any")
316
+
317
+ if warn_unreachable:
318
+ cli_args.append("--warn-unreachable")
319
+
320
+ if allow_untyped_globals:
321
+ cli_args.append("--allow-untyped-globals")
322
+
323
+ if allow_redefinition:
324
+ cli_args.append("--allow-redefinition")
325
+
326
+ if no_implicit_reexport:
327
+ cli_args.append("--no-implicit-reexport")
328
+
329
+ if strict_equality:
330
+ cli_args.append("--strict-equality")
331
+
332
+ if strict_concatenate:
333
+ cli_args.append("--strict-concatenate")
334
+
335
+ if strict:
336
+ cli_args.append("--strict")
337
+
338
+ if disable_error_code:
339
+ cli_args.append("--disable-error-code")
340
+ cli_args.append(disable_error_code)
341
+
342
+ if enable_error_code:
343
+ cli_args.append("--enable-error-code")
344
+ cli_args.append(enable_error_code)
345
+
346
+ if show_error_context:
347
+ cli_args.append("--show-error-context")
348
+
349
+ if show_column_numbers:
350
+ cli_args.append("--show-column-numbers")
351
+
352
+ if show_error_end:
353
+ cli_args.append("--show-error-end")
354
+
355
+ if hide_error_codes:
356
+ cli_args.append("--hide-error-codes")
357
+
358
+ if pretty:
359
+ cli_args.append("--pretty")
360
+
361
+ if no_color_output:
362
+ cli_args.append("--no-color-output")
363
+
364
+ if no_error_summary:
365
+ cli_args.append("--no-error-summary")
366
+
367
+ if show_absolute_path:
368
+ cli_args.append("--show-absolute-path")
369
+
370
+ if no_incremental:
371
+ cli_args.append("--no-incremental")
372
+
373
+ if cache_dir:
374
+ cli_args.append("--cache-dir")
375
+ cli_args.append(cache_dir)
376
+
377
+ if sqlite_cache:
378
+ cli_args.append("--sqlite-cache")
379
+
380
+ if cache_fine_grained:
381
+ cli_args.append("--cache-fine-grained")
382
+
383
+ if skip_version_check:
384
+ cli_args.append("--skip-version-check")
385
+
386
+ if skip_cache_mtime_checks:
387
+ cli_args.append("--skip-cache-mtime-checks")
388
+
389
+ if pdb:
390
+ cli_args.append("--pdb")
391
+
392
+ if show_traceback:
393
+ cli_args.append("--show-traceback")
394
+
395
+ if raise_exceptions:
396
+ cli_args.append("--raise-exceptions")
397
+
398
+ if custom_typing_module:
399
+ cli_args.append("--custom-typing-module")
400
+ cli_args.append(custom_typing_module)
401
+
402
+ if disable_recursive_aliases:
403
+ cli_args.append("--disable-recursive-aliases")
404
+
405
+ if custom_typeshed_dir:
406
+ cli_args.append("--custom-typeshed-dir")
407
+ cli_args.append(custom_typeshed_dir)
408
+
409
+ if warn_incomplete_stub:
410
+ cli_args.append("--warn-incomplete-stub")
411
+
412
+ if shadow_file:
413
+ cli_args.append("--shadow-file")
414
+ cli_args.extend(shadow_file)
415
+
416
+ if any_exprs_report:
417
+ cli_args.append("--any-exprs-report")
418
+ cli_args.append(any_exprs_report)
419
+
420
+ if cobertura_xml_report:
421
+ cli_args.append("--cobertura-xml-report")
422
+ cli_args.append(cobertura_xml_report)
423
+
424
+ if html_report:
425
+ cli_args.append("--html-report")
426
+ cli_args.append(html_report)
427
+
428
+ if linecount_report:
429
+ cli_args.append("--linecount-report")
430
+ cli_args.append(linecount_report)
431
+
432
+ if linecoverage_report:
433
+ cli_args.append("--linecoverage-report")
434
+ cli_args.append(linecoverage_report)
435
+
436
+ if lineprecision_report:
437
+ cli_args.append("--lineprecision-report")
438
+ cli_args.append(lineprecision_report)
439
+
440
+ if txt_report:
441
+ cli_args.append("--txt-report")
442
+ cli_args.append(txt_report)
443
+
444
+ if xml_report:
445
+ cli_args.append("--xml-report")
446
+ cli_args.append(xml_report)
447
+
448
+ if xslt_html_report:
449
+ cli_args.append("--xslt-html-report")
450
+ cli_args.append(xslt_html_report)
451
+
452
+ if xslt_txt_report:
453
+ cli_args.append("--xslt-txt-report")
454
+ cli_args.append(xslt_txt_report)
455
+
456
+ if junit_xml:
457
+ cli_args.append("--junit-xml")
458
+ cli_args.append(junit_xml)
459
+
460
+ if find_occurrences:
461
+ cli_args.append("--find-occurrences")
462
+ cli_args.append(find_occurrences)
463
+
464
+ if scripts_are_modules:
465
+ cli_args.append("--scripts-are-modules")
466
+
467
+ if install_types:
468
+ cli_args.append("--install-types")
469
+
470
+ if non_interactive:
471
+ cli_args.append("--non-interactive")
472
+
473
+ if explicit_package_bases:
474
+ cli_args.append("--explicit-package-bases")
475
+
476
+ if exclude:
477
+ cli_args.append("--exclude")
478
+ cli_args.append(exclude)
479
+
480
+ if module:
481
+ cli_args.append("--module")
482
+ cli_args.append(module)
483
+
484
+ if package:
485
+ cli_args.append("--package")
486
+ cli_args.append(package)
487
+
488
+ if command:
489
+ cli_args.append("--command")
490
+ cli_args.append(command)
491
+
492
+ super().__init__(cli_args)
493
+
494
+ def __call__(self) -> None:
495
+ from mypy.main import main as run_mypy
496
+
497
+ return run_mypy(
498
+ args=self.cli_args,
499
+ stdout=LazyStdout(),
500
+ stderr=LazyStderr(),
501
+ clean_exit=True,
502
+ )