| 1 |
-- End-to-end test cases for the daemon (dmypy). |
| 2 |
-- These are special because they run multiple shell commands. |
| 3 |
|
| 4 |
[case testDaemonStartStop] |
| 5 |
$ dmypy start -- --follow-imports=error |
| 6 |
Daemon started |
| 7 |
$ dmypy stop |
| 8 |
Daemon stopped |
| 9 |
|
| 10 |
[case testDaemonBasic] |
| 11 |
$ dmypy start -- --follow-imports=error |
| 12 |
Daemon started |
| 13 |
$ dmypy check -- foo.py |
| 14 |
Success: no issues found in 1 source file |
| 15 |
$ dmypy recheck |
| 16 |
Success: no issues found in 1 source file |
| 17 |
$ dmypy stop |
| 18 |
Daemon stopped |
| 19 |
[file foo.py] |
| 20 |
def f(): pass |
| 21 |
|
| 22 |
[case testDaemonRun] |
| 23 |
$ dmypy run -- foo.py --follow-imports=error |
| 24 |
Daemon started |
| 25 |
Success: no issues found in 1 source file |
| 26 |
$ dmypy stop |
| 27 |
Daemon stopped |
| 28 |
[file foo.py] |
| 29 |
def f(): pass |
| 30 |
|
| 31 |
[case testDaemonRunIgnoreMissingImports] |
| 32 |
$ dmypy run -- foo.py --follow-imports=error --ignore-missing-imports |
| 33 |
Daemon started |
| 34 |
Success: no issues found in 1 source file |
| 35 |
$ dmypy stop |
| 36 |
Daemon stopped |
| 37 |
[file foo.py] |
| 38 |
def f(): pass |
| 39 |
|
| 40 |
[case testDaemonRunErrorCodes] |
| 41 |
$ dmypy run -- foo.py --follow-imports=error --disable-error-code=type-abstract |
| 42 |
Daemon started |
| 43 |
Success: no issues found in 1 source file |
| 44 |
$ dmypy stop |
| 45 |
Daemon stopped |
| 46 |
[file foo.py] |
| 47 |
def f(): pass |
| 48 |
|
| 49 |
[case testDaemonRunCombinedOptions] |
| 50 |
$ dmypy run -- foo.py --follow-imports=error --ignore-missing-imports --disable-error-code=type-abstract |
| 51 |
Daemon started |
| 52 |
Success: no issues found in 1 source file |
| 53 |
$ dmypy stop |
| 54 |
Daemon stopped |
| 55 |
[file foo.py] |
| 56 |
def f(): pass |
| 57 |
|
| 58 |
[case testDaemonIgnoreConfigFiles] |
| 59 |
$ dmypy start -- --follow-imports=error |
| 60 |
Daemon started |
| 61 |
[file mypy.ini] |
| 62 |
\[mypy] |
| 63 |
files = ./foo.py |
| 64 |
|
| 65 |
[case testDaemonRunMultipleStrict] |
| 66 |
$ dmypy run -- foo.py --strict --follow-imports=error |
| 67 |
Daemon started |
| 68 |
foo.py:1: error: Function is missing a return type annotation |
| 69 |
foo.py:1: note: Use "-> None" if function does not return a value |
| 70 |
Found 1 error in 1 file (checked 1 source file) |
| 71 |
== Return code: 1 |
| 72 |
$ dmypy run -- bar.py --strict --follow-imports=error |
| 73 |
bar.py:1: error: Function is missing a return type annotation |
| 74 |
bar.py:1: note: Use "-> None" if function does not return a value |
| 75 |
Found 1 error in 1 file (checked 1 source file) |
| 76 |
== Return code: 1 |
| 77 |
$ dmypy run -- foo.py --strict --follow-imports=error |
| 78 |
foo.py:1: error: Function is missing a return type annotation |
| 79 |
foo.py:1: note: Use "-> None" if function does not return a value |
| 80 |
Found 1 error in 1 file (checked 1 source file) |
| 81 |
== Return code: 1 |
| 82 |
[file foo.py] |
| 83 |
def f(): pass |
| 84 |
[file bar.py] |
| 85 |
def f(): pass |
| 86 |
|
| 87 |
[case testDaemonRunRestart] |
| 88 |
$ dmypy run -- foo.py --follow-imports=error |
| 89 |
Daemon started |
| 90 |
Success: no issues found in 1 source file |
| 91 |
$ dmypy run -- foo.py --follow-imports=error |
| 92 |
Success: no issues found in 1 source file |
| 93 |
$ {python} -c "print('[mypy]')" >mypy.ini |
| 94 |
$ {python} -c "print('disallow_untyped_defs = True')" >>mypy.ini |
| 95 |
$ dmypy run -- foo.py --follow-imports=error |
| 96 |
Restarting: configuration changed |
| 97 |
Daemon stopped |
| 98 |
Daemon started |
| 99 |
foo.py:1: error: Function is missing a return type annotation |
| 100 |
foo.py:1: note: Use "-> None" if function does not return a value |
| 101 |
Found 1 error in 1 file (checked 1 source file) |
| 102 |
== Return code: 1 |
| 103 |
$ {python} -c "print('def f() -> None: pass')" >foo.py |
| 104 |
$ dmypy run -- foo.py --follow-imports=error |
| 105 |
Success: no issues found in 1 source file |
| 106 |
$ dmypy stop |
| 107 |
Daemon stopped |
| 108 |
[file foo.py] |
| 109 |
def f(): pass |
| 110 |
|
| 111 |
[case testDaemonRunRestartPretty] |
| 112 |
$ dmypy run -- foo.py --follow-imports=error --pretty |
| 113 |
Daemon started |
| 114 |
Success: no issues found in 1 source file |
| 115 |
$ dmypy run -- foo.py --follow-imports=error --pretty |
| 116 |
Success: no issues found in 1 source file |
| 117 |
$ {python} -c "print('[mypy]')" >mypy.ini |
| 118 |
$ {python} -c "print('disallow_untyped_defs = True')" >>mypy.ini |
| 119 |
$ dmypy run -- foo.py --follow-imports=error --pretty |
| 120 |
Restarting: configuration changed |
| 121 |
Daemon stopped |
| 122 |
Daemon started |
| 123 |
foo.py:1: error: Function is missing a return type annotation |
| 124 |
def f(): |
| 125 |
^~~~~~~~ |
| 126 |
foo.py:1: note: Use "-> None" if function does not return a value |
| 127 |
Found 1 error in 1 file (checked 1 source file) |
| 128 |
== Return code: 1 |
| 129 |
$ {python} -c "print('def f() -> None: pass')" >foo.py |
| 130 |
$ dmypy run -- foo.py --follow-imports=error --pretty |
| 131 |
Success: no issues found in 1 source file |
| 132 |
$ dmypy stop |
| 133 |
Daemon stopped |
| 134 |
[file foo.py] |
| 135 |
def f(): |
| 136 |
pass |
| 137 |
|
| 138 |
[case testDaemonRunRestartPluginVersion] |
| 139 |
$ dmypy run -- foo.py --no-error-summary |
| 140 |
Daemon started |
| 141 |
$ {python} -c "print(' ')" >> plug.py |
| 142 |
$ dmypy run -- foo.py --no-error-summary |
| 143 |
Restarting: plugins changed |
| 144 |
Daemon stopped |
| 145 |
Daemon started |
| 146 |
$ dmypy stop |
| 147 |
Daemon stopped |
| 148 |
[file mypy.ini] |
| 149 |
\[mypy] |
| 150 |
follow_imports = error |
| 151 |
plugins = plug.py |
| 152 |
[file foo.py] |
| 153 |
pass |
| 154 |
[file plug.py] |
| 155 |
from mypy.plugin import Plugin |
| 156 |
class Dummy(Plugin): pass |
| 157 |
def plugin(version): return Dummy |
| 158 |
|
| 159 |
[case testDaemonRunRestartGlobs] |
| 160 |
-- Ensure dmypy is not restarted if the configuration doesn't change and it contains globs |
| 161 |
-- Note: Backslash path separator in output is replaced with forward slash so the same test succeeds on Windows as well |
| 162 |
$ dmypy run -- foo --follow-imports=error |
| 163 |
Daemon started |
| 164 |
foo/lol.py:1: error: Name "fail" is not defined |
| 165 |
Found 1 error in 1 file (checked 3 source files) |
| 166 |
== Return code: 1 |
| 167 |
$ dmypy run -- foo --follow-imports=error |
| 168 |
foo/lol.py:1: error: Name "fail" is not defined |
| 169 |
Found 1 error in 1 file (checked 3 source files) |
| 170 |
== Return code: 1 |
| 171 |
$ {python} -c "print('[mypy]')" >mypy.ini |
| 172 |
$ {python} -c "print('ignore_errors=True')" >>mypy.ini |
| 173 |
$ dmypy run -- foo --follow-imports=error |
| 174 |
Restarting: configuration changed |
| 175 |
Daemon stopped |
| 176 |
Daemon started |
| 177 |
Success: no issues found in 3 source files |
| 178 |
$ dmypy stop |
| 179 |
Daemon stopped |
| 180 |
[file mypy.ini] |
| 181 |
\[mypy] |
| 182 |
ignore_errors = True |
| 183 |
\[mypy-*.lol] |
| 184 |
ignore_errors = False |
| 185 |
|
| 186 |
[file foo/__init__.py] |
| 187 |
[file foo/lol.py] |
| 188 |
fail |
| 189 |
[file foo/ok.py] |
| 190 |
a: int = 1 |
| 191 |
|
| 192 |
[case testDaemonStatusKillRestartRecheck] |
| 193 |
$ dmypy status |
| 194 |
No status file found |
| 195 |
== Return code: 2 |
| 196 |
$ dmypy stop |
| 197 |
No status file found |
| 198 |
== Return code: 2 |
| 199 |
$ dmypy kill |
| 200 |
No status file found |
| 201 |
== Return code: 2 |
| 202 |
$ dmypy recheck |
| 203 |
No status file found |
| 204 |
== Return code: 2 |
| 205 |
$ dmypy start -- --follow-imports=error --no-error-summary |
| 206 |
Daemon started |
| 207 |
$ dmypy status |
| 208 |
Daemon is up and running |
| 209 |
$ dmypy start |
| 210 |
Daemon is still alive |
| 211 |
== Return code: 2 |
| 212 |
$ dmypy restart -- --follow-imports=error --no-error-summary |
| 213 |
Daemon stopped |
| 214 |
Daemon started |
| 215 |
$ dmypy stop |
| 216 |
Daemon stopped |
| 217 |
$ dmypy status |
| 218 |
No status file found |
| 219 |
== Return code: 2 |
| 220 |
$ dmypy restart -- --follow-imports=error --no-error-summary |
| 221 |
Daemon started |
| 222 |
$ dmypy recheck |
| 223 |
Command 'recheck' is only valid after a 'check' command |
| 224 |
== Return code: 2 |
| 225 |
$ dmypy kill |
| 226 |
Daemon killed |
| 227 |
$ dmypy status |
| 228 |
Daemon has died |
| 229 |
== Return code: 2 |
| 230 |
|
| 231 |
[case testDaemonRecheck] |
| 232 |
$ dmypy start -- --follow-imports=error --no-error-summary |
| 233 |
Daemon started |
| 234 |
$ dmypy check foo.py bar.py |
| 235 |
$ dmypy recheck |
| 236 |
$ dmypy recheck --update foo.py --remove bar.py sir_not_appearing_in_this_film.py |
| 237 |
foo.py:1: error: Import of "bar" ignored [misc] |
| 238 |
foo.py:1: note: (Using --follow-imports=error, module not passed on command line) |
| 239 |
== Return code: 1 |
| 240 |
$ dmypy recheck --update bar.py |
| 241 |
$ dmypy recheck --update sir_not_appearing_in_this_film.py |
| 242 |
$ dmypy recheck --update --remove |
| 243 |
$ dmypy stop |
| 244 |
Daemon stopped |
| 245 |
[file foo.py] |
| 246 |
import bar |
| 247 |
[file bar.py] |
| 248 |
pass |
| 249 |
|
| 250 |
[case testDaemonTimeout] |
| 251 |
$ dmypy start --timeout 1 -- --follow-imports=error |
| 252 |
Daemon started |
| 253 |
$ {python} -c "import time;time.sleep(1)" |
| 254 |
$ dmypy status |
| 255 |
No status file found |
| 256 |
== Return code: 2 |
| 257 |
|
| 258 |
[case testDaemonRunNoTarget] |
| 259 |
$ dmypy run -- --follow-imports=error |
| 260 |
Daemon started |
| 261 |
mypy-daemon: error: Missing target module, package, files, or command. |
| 262 |
== Return code: 2 |
| 263 |
$ dmypy stop |
| 264 |
Daemon stopped |
| 265 |
|
| 266 |
[case testDaemonRunTwoFilesFullTypeshed] |
| 267 |
$ dmypy run x.py |
| 268 |
Daemon started |
| 269 |
Success: no issues found in 1 source file |
| 270 |
$ dmypy run y.py |
| 271 |
Success: no issues found in 1 source file |
| 272 |
$ dmypy run x.py |
| 273 |
Success: no issues found in 1 source file |
| 274 |
[file x.py] |
| 275 |
[file y.py] |
| 276 |
|
| 277 |
[case testDaemonCheckTwoFilesFullTypeshed] |
| 278 |
$ dmypy start |
| 279 |
Daemon started |
| 280 |
$ dmypy check foo.py |
| 281 |
foo.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] |
| 282 |
Found 1 error in 1 file (checked 1 source file) |
| 283 |
== Return code: 1 |
| 284 |
$ dmypy check bar.py |
| 285 |
Success: no issues found in 1 source file |
| 286 |
$ dmypy check foo.py |
| 287 |
foo.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] |
| 288 |
Found 1 error in 1 file (checked 1 source file) |
| 289 |
== Return code: 1 |
| 290 |
[file foo.py] |
| 291 |
from bar import add |
| 292 |
x: str = add("a", "b") |
| 293 |
x_error: int = add("a", "b") |
| 294 |
[file bar.py] |
| 295 |
def add(a, b) -> str: |
| 296 |
return a + b |
| 297 |
|
| 298 |
[case testDaemonWarningSuccessExitCode-posix] |
| 299 |
$ dmypy run -- foo.py --follow-imports=error --python-version=3.11 |
| 300 |
Daemon started |
| 301 |
foo.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs |
| 302 |
Success: no issues found in 1 source file |
| 303 |
$ echo $? |
| 304 |
0 |
| 305 |
$ dmypy stop |
| 306 |
Daemon stopped |
| 307 |
[file foo.py] |
| 308 |
def foo(): |
| 309 |
a: int = 1 |
| 310 |
print(a + "2") |
| 311 |
|
| 312 |
-- this is carefully constructed to be able to break if the quickstart system lets |
| 313 |
-- something through incorrectly. in particular, the files need to have the same size |
| 314 |
[case testDaemonQuickstart] |
| 315 |
$ {python} -c "print('x=1')" >foo.py |
| 316 |
$ {python} -c "print('x=1')" >bar.py |
| 317 |
$ mypy --local-partial-types --cache-fine-grained --follow-imports=error --no-sqlite-cache --python-version=3.11 -- foo.py bar.py |
| 318 |
Success: no issues found in 2 source files |
| 319 |
$ {python} -c "import shutil; shutil.copy('.mypy_cache/3.11/bar.meta.ff', 'asdf.ff')" |
| 320 |
-- update bar's timestamp but don't change the file |
| 321 |
$ {python} -c "import time;time.sleep(1)" |
| 322 |
$ {python} -c "print('x=1')" >bar.py |
| 323 |
$ dmypy run -- foo.py bar.py --follow-imports=error --use-fine-grained-cache --no-sqlite-cache --python-version=3.11 |
| 324 |
Daemon started |
| 325 |
Success: no issues found in 2 source files |
| 326 |
$ dmypy status --fswatcher-dump-file test.json |
| 327 |
Daemon is up and running |
| 328 |
$ dmypy stop |
| 329 |
Daemon stopped |
| 330 |
-- copy the original bar cache file back so that the mtime mismatches |
| 331 |
$ {python} -c "import shutil; shutil.copy('asdf.ff', '.mypy_cache/3.11/bar.meta.ff')" |
| 332 |
-- sleep guarantees timestamp changes |
| 333 |
$ {python} -c "import time;time.sleep(1)" |
| 334 |
$ {python} -c "print('lol')" >foo.py |
| 335 |
$ dmypy run --log-file=log -- foo.py bar.py --follow-imports=error --use-fine-grained-cache --no-sqlite-cache --python-version=3.11 --quickstart-file test.json |
| 336 |
Daemon started |
| 337 |
foo.py:1: error: Name "lol" is not defined |
| 338 |
Found 1 error in 1 file (checked 2 source files) |
| 339 |
== Return code: 1 |
| 340 |
-- make sure no errors made it to the log file |
| 341 |
$ {python} -c "import sys; sys.stdout.write(open('log').read())" |
| 342 |
-- make sure the meta file didn't get updated. we use this as an imperfect proxy for |
| 343 |
-- whether the source file got rehashed, which we don't want it to have been. |
| 344 |
$ {python} -c "x = open('.mypy_cache/3.11/bar.meta.ff', 'rb').read(); y = open('asdf.ff', 'rb').read(); assert x == y" |
| 345 |
|
| 346 |
[case testDaemonSuggest] |
| 347 |
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary |
| 348 |
Daemon started |
| 349 |
$ dmypy suggest foo:foo |
| 350 |
Command 'suggest' is only valid after a 'check' command (that produces no parse errors) |
| 351 |
== Return code: 2 |
| 352 |
$ dmypy check foo.py bar.py |
| 353 |
$ dmypy suggest foo.bar |
| 354 |
Unknown function foo.bar |
| 355 |
== Return code: 2 |
| 356 |
$ dmypy suggest foo.var |
| 357 |
Object foo.var is not a function |
| 358 |
== Return code: 2 |
| 359 |
$ dmypy suggest foo.Foo.var |
| 360 |
Unknown class foo.Foo |
| 361 |
== Return code: 2 |
| 362 |
$ dmypy suggest foo.Bar.baz |
| 363 |
Unknown method foo.Bar.baz |
| 364 |
== Return code: 2 |
| 365 |
$ dmypy suggest foo.foo.baz |
| 366 |
Object foo.foo is not a class |
| 367 |
== Return code: 2 |
| 368 |
$ dmypy suggest --callsites foo.foo |
| 369 |
bar.py:3: (str) |
| 370 |
bar.py:4: (arg=str) |
| 371 |
$ dmypy suggest foo.foo |
| 372 |
(str) -> int |
| 373 |
$ {python} -c "import shutil; shutil.copy('foo2.py', 'foo.py')" |
| 374 |
$ dmypy check foo.py bar.py |
| 375 |
bar.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment] |
| 376 |
== Return code: 1 |
| 377 |
[file foo.py] |
| 378 |
def foo(arg): |
| 379 |
return 12 |
| 380 |
class Bar: |
| 381 |
def bar(self): pass |
| 382 |
var = 0 |
| 383 |
[file foo2.py] |
| 384 |
def foo(arg: str) -> int: |
| 385 |
return 12 |
| 386 |
class Bar: |
| 387 |
def bar(self) -> None: pass |
| 388 |
var = 0 |
| 389 |
[file bar.py] |
| 390 |
from foo import foo |
| 391 |
def bar() -> None: |
| 392 |
x = foo('abc') # type: str |
| 393 |
foo(arg='xyz') |
| 394 |
|
| 395 |
[case testDaemonInspectCheck] |
| 396 |
$ dmypy start |
| 397 |
Daemon started |
| 398 |
$ dmypy check foo.py |
| 399 |
Success: no issues found in 1 source file |
| 400 |
$ dmypy check foo.py --export-types |
| 401 |
Success: no issues found in 1 source file |
| 402 |
$ dmypy inspect foo.py:1:1 |
| 403 |
"int" |
| 404 |
[file foo.py] |
| 405 |
x = 1 |
| 406 |
|
| 407 |
[case testDaemonInspectRun] |
| 408 |
$ dmypy run test1.py |
| 409 |
Daemon started |
| 410 |
Success: no issues found in 1 source file |
| 411 |
$ dmypy run test2.py |
| 412 |
Success: no issues found in 1 source file |
| 413 |
$ dmypy run test1.py --export-types |
| 414 |
Success: no issues found in 1 source file |
| 415 |
$ dmypy inspect test1.py:1:1 |
| 416 |
"int" |
| 417 |
[file test1.py] |
| 418 |
a: int |
| 419 |
[file test2.py] |
| 420 |
a: str |
| 421 |
|
| 422 |
[case testDaemonGetType] |
| 423 |
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary --python-version 3.10 |
| 424 |
Daemon started |
| 425 |
$ dmypy inspect foo:1:2:3:4 |
| 426 |
Command "inspect" is only valid after a "check" command (that produces no parse errors) |
| 427 |
== Return code: 2 |
| 428 |
$ dmypy check foo.py --export-types |
| 429 |
foo.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] |
| 430 |
== Return code: 1 |
| 431 |
$ dmypy inspect foo:1 |
| 432 |
Format should be file:line:column[:end_line:end_column] |
| 433 |
== Return code: 2 |
| 434 |
$ dmypy inspect foo:1:2:3 |
| 435 |
Source file is not a Python file |
| 436 |
== Return code: 2 |
| 437 |
$ dmypy inspect foo.py:1:2:a:b |
| 438 |
invalid literal for int() with base 10: 'a' |
| 439 |
== Return code: 2 |
| 440 |
$ dmypy inspect foo.pyc:1:1:2:2 |
| 441 |
Source file is not a Python file |
| 442 |
== Return code: 2 |
| 443 |
$ dmypy inspect bar/baz.py:1:1:2:2 |
| 444 |
Unknown module: bar/baz.py |
| 445 |
== Return code: 1 |
| 446 |
$ dmypy inspect foo.py:3:1:1:1 |
| 447 |
"end_line" must not be before "line" |
| 448 |
== Return code: 2 |
| 449 |
$ dmypy inspect foo.py:3:3:3:1 |
| 450 |
"end_column" must be after "column" |
| 451 |
== Return code: 2 |
| 452 |
$ dmypy inspect foo.py:3:10:3:17 |
| 453 |
"str" |
| 454 |
$ dmypy inspect foo.py:3:10:3:17 -vv |
| 455 |
"builtins.str" |
| 456 |
$ dmypy inspect foo.py:9:9:9:11 |
| 457 |
"int" |
| 458 |
$ dmypy inspect foo.py:11:1:11:3 |
| 459 |
"Callable[[int | None], None]" |
| 460 |
$ dmypy inspect foo.py:11:1:13:1 |
| 461 |
"None" |
| 462 |
$ dmypy inspect foo.py:1:2:3:4 |
| 463 |
Can't find expression at span 1:2:3:4 |
| 464 |
== Return code: 1 |
| 465 |
$ dmypy inspect foo.py:17:5:17:5 |
| 466 |
No known type available for "NameExpr" (maybe unreachable or try --force-reload) |
| 467 |
== Return code: 1 |
| 468 |
|
| 469 |
[file foo.py] |
| 470 |
from typing import Optional |
| 471 |
|
| 472 |
x: int = "no way" # line 3 |
| 473 |
|
| 474 |
def foo(arg: Optional[int] = None) -> None: |
| 475 |
if arg is None: |
| 476 |
arg |
| 477 |
else: |
| 478 |
arg # line 9 |
| 479 |
|
| 480 |
foo( |
| 481 |
# multiline |
| 482 |
) |
| 483 |
|
| 484 |
def unreachable(x: int) -> None: |
| 485 |
return |
| 486 |
x # line 17 |
| 487 |
|
| 488 |
[case testDaemonGetTypeInexact] |
| 489 |
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary |
| 490 |
Daemon started |
| 491 |
$ dmypy check foo.py --export-types |
| 492 |
$ dmypy inspect foo.py:1:a |
| 493 |
invalid literal for int() with base 10: 'a' |
| 494 |
== Return code: 2 |
| 495 |
$ dmypy inspect foo.pyc:1:2 |
| 496 |
Source file is not a Python file |
| 497 |
== Return code: 2 |
| 498 |
$ dmypy inspect bar/baz.py:1:2 |
| 499 |
Unknown module: bar/baz.py |
| 500 |
== Return code: 1 |
| 501 |
$ dmypy inspect foo.py:7:5 --include-span |
| 502 |
7:5:7:5 -> "int" |
| 503 |
7:5:7:11 -> "int" |
| 504 |
7:1:7:12 -> "None" |
| 505 |
$ dmypy inspect foo.py:7:5 --include-kind |
| 506 |
NameExpr -> "int" |
| 507 |
OpExpr -> "int" |
| 508 |
CallExpr -> "None" |
| 509 |
$ dmypy inspect foo.py:7:5 --include-span --include-kind |
| 510 |
NameExpr:7:5:7:5 -> "int" |
| 511 |
OpExpr:7:5:7:11 -> "int" |
| 512 |
CallExpr:7:1:7:12 -> "None" |
| 513 |
$ dmypy inspect foo.py:7:5 -vv |
| 514 |
"builtins.int" |
| 515 |
"builtins.int" |
| 516 |
"None" |
| 517 |
$ dmypy inspect foo.py:7:5 -vv --limit=1 |
| 518 |
"builtins.int" |
| 519 |
$ dmypy inspect foo.py:7:3 |
| 520 |
"Callable[[int], None]" |
| 521 |
"None" |
| 522 |
$ dmypy inspect foo.py:1:2 |
| 523 |
Can't find any expressions at position 1:2 |
| 524 |
== Return code: 1 |
| 525 |
$ dmypy inspect foo.py:11:5 --force-reload |
| 526 |
No known type available for "NameExpr" (maybe unreachable) |
| 527 |
No known type available for "OpExpr" (maybe unreachable) |
| 528 |
== Return code: 1 |
| 529 |
|
| 530 |
[file foo.py] |
| 531 |
from typing import Optional |
| 532 |
|
| 533 |
def foo(x: int) -> None: ... |
| 534 |
|
| 535 |
a: int |
| 536 |
b: int |
| 537 |
foo(a and b) # line 7 |
| 538 |
|
| 539 |
def unreachable(x: int, y: int) -> None: |
| 540 |
return |
| 541 |
x and y # line 11 |
| 542 |
|
| 543 |
[case testDaemonGetAttrs] |
| 544 |
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary |
| 545 |
Daemon started |
| 546 |
$ dmypy check foo.py bar.py --export-types |
| 547 |
$ dmypy inspect foo.py:9:1 --show attrs --include-span --include-kind -vv |
| 548 |
NameExpr:9:1:9:1 -> {"foo.C": ["a", "x", "y"], "foo.B": ["a", "b"]} |
| 549 |
$ dmypy inspect foo.py:11:10 --show attrs |
| 550 |
No known type available for "StrExpr" (maybe unreachable or try --force-reload) |
| 551 |
== Return code: 1 |
| 552 |
$ dmypy inspect foo.py:1:1 --show attrs |
| 553 |
Can't find any expressions at position 1:1 |
| 554 |
== Return code: 1 |
| 555 |
$ dmypy inspect --show attrs bar.py:10:1 |
| 556 |
{"A": ["z"], "B": ["z"]} |
| 557 |
$ dmypy inspect --show attrs bar.py:10:1 --union-attrs |
| 558 |
{"A": ["x", "z"], "B": ["y", "z"]} |
| 559 |
|
| 560 |
[file foo.py] |
| 561 |
class B: |
| 562 |
def b(self) -> int: return 0 |
| 563 |
a: int |
| 564 |
class C(B): |
| 565 |
a: int |
| 566 |
y: int |
| 567 |
def x(self) -> int: return 0 |
| 568 |
|
| 569 |
v: C # line 9 |
| 570 |
if False: |
| 571 |
"unreachable" |
| 572 |
|
| 573 |
[file bar.py] |
| 574 |
from typing import Union |
| 575 |
|
| 576 |
class A: |
| 577 |
x: int |
| 578 |
z: int |
| 579 |
class B: |
| 580 |
y: int |
| 581 |
z: int |
| 582 |
var: Union[A, B] |
| 583 |
var # line 10 |
| 584 |
|
| 585 |
[case testDaemonGetDefinition] |
| 586 |
$ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary |
| 587 |
Daemon started |
| 588 |
$ dmypy check foo.py bar/baz.py bar/__init__.py --export-types |
| 589 |
$ dmypy inspect foo.py:5:1 --show definition |
| 590 |
foo.py:4:1:y |
| 591 |
$ dmypy inspect foo.py:2:3 --show definition --include-span --include-kind -vv |
| 592 |
MemberExpr:2:1:2:7 -> bar/baz.py:3:5:Alias |
| 593 |
$ dmypy inspect foo.py:3:1 --show definition |
| 594 |
Cannot find definition for "NameExpr" at 3:1:3:1 |
| 595 |
== Return code: 1 |
| 596 |
$ dmypy inspect foo.py:4:6 --show definition |
| 597 |
No name or member expressions at 4:6 |
| 598 |
== Return code: 1 |
| 599 |
$ dmypy inspect foo.py:7:1:7:6 --show definition |
| 600 |
bar/baz.py:4:5:attr |
| 601 |
$ dmypy inspect foo.py:10:10 --show definition --include-span |
| 602 |
10:1:10:12 -> bar/baz.py:6:1:test |
| 603 |
$ dmypy inspect foo.py:14:6 --show definition --include-span --include-kind |
| 604 |
NameExpr:14:5:14:7 -> foo.py:13:9:arg |
| 605 |
MemberExpr:14:5:14:9 -> bar/baz.py:9:5:x, bar/baz.py:11:5:x |
| 606 |
|
| 607 |
[file foo.py] |
| 608 |
from bar.baz import A, B, C |
| 609 |
C.Alias |
| 610 |
x # type: ignore |
| 611 |
y = 42 |
| 612 |
y # line 5 |
| 613 |
z = C() |
| 614 |
z.attr |
| 615 |
|
| 616 |
import bar |
| 617 |
bar.baz.test() # line 10 |
| 618 |
|
| 619 |
from typing import Union |
| 620 |
def foo(arg: Union[A, B]) -> None: |
| 621 |
arg.x |
| 622 |
|
| 623 |
[file bar/__init__.py] |
| 624 |
[file bar/baz.py] |
| 625 |
from typing import Union |
| 626 |
class C: |
| 627 |
Alias = Union[int, str] |
| 628 |
attr = 42 |
| 629 |
|
| 630 |
def test() -> None: ... # line 6 |
| 631 |
|
| 632 |
class A: |
| 633 |
x: int |
| 634 |
class B: |
| 635 |
x: int |
| 636 |
|
| 637 |
[case testDaemonInspectSelectCorrectFile] |
| 638 |
$ dmypy run test.py --export-types |
| 639 |
Daemon started |
| 640 |
Success: no issues found in 1 source file |
| 641 |
$ dmypy inspect demo/test.py:1:1 |
| 642 |
"int" |
| 643 |
$ dmypy inspect test.py:1:1 |
| 644 |
"str" |
| 645 |
[file test.py] |
| 646 |
b: str |
| 647 |
from demo.test import a |
| 648 |
[file demo/test.py] |
| 649 |
a: int |
| 650 |
|
| 651 |
[case testUnusedTypeIgnorePreservedOnRerun] |
| 652 |
-- Regression test for https://github.com/python/mypy/issues/9655 |
| 653 |
$ dmypy start -- --warn-unused-ignores --no-error-summary --hide-error-codes |
| 654 |
Daemon started |
| 655 |
$ dmypy check -- bar.py |
| 656 |
bar.py:2: error: Unused "type: ignore" comment |
| 657 |
== Return code: 1 |
| 658 |
$ dmypy check -- bar.py |
| 659 |
bar.py:2: error: Unused "type: ignore" comment |
| 660 |
== Return code: 1 |
| 661 |
|
| 662 |
[file foo/__init__.py] |
| 663 |
[file foo/empty.py] |
| 664 |
[file bar.py] |
| 665 |
from foo.empty import * |
| 666 |
a = 1 # type: ignore |
| 667 |
|
| 668 |
[case testTypeIgnoreWithoutCodePreservedOnRerun] |
| 669 |
-- Regression test for https://github.com/python/mypy/issues/9655 |
| 670 |
$ dmypy start -- --enable-error-code ignore-without-code --no-error-summary |
| 671 |
Daemon started |
| 672 |
$ dmypy check -- bar.py |
| 673 |
bar.py:2: error: "type: ignore" comment without error code [ignore-without-code] |
| 674 |
== Return code: 1 |
| 675 |
$ dmypy check -- bar.py |
| 676 |
bar.py:2: error: "type: ignore" comment without error code [ignore-without-code] |
| 677 |
== Return code: 1 |
| 678 |
|
| 679 |
[file foo/__init__.py] |
| 680 |
[file foo/empty.py] |
| 681 |
[file bar.py] |
| 682 |
from foo.empty import * |
| 683 |
a = 1 # type: ignore |
| 684 |
|
| 685 |
[case testPossiblyUndefinedVarsPreservedAfterRerun] |
| 686 |
-- Regression test for https://github.com/python/mypy/issues/9655 |
| 687 |
$ dmypy start -- --enable-error-code possibly-undefined --no-error-summary |
| 688 |
Daemon started |
| 689 |
$ dmypy check -- bar.py |
| 690 |
bar.py:4: error: Name "a" may be undefined [possibly-undefined] |
| 691 |
== Return code: 1 |
| 692 |
$ dmypy check -- bar.py |
| 693 |
bar.py:4: error: Name "a" may be undefined [possibly-undefined] |
| 694 |
== Return code: 1 |
| 695 |
|
| 696 |
[file foo/__init__.py] |
| 697 |
[file foo/empty.py] |
| 698 |
[file bar.py] |
| 699 |
from foo.empty import * |
| 700 |
if False: |
| 701 |
a = 1 |
| 702 |
a |
| 703 |
|
| 704 |
[case testUnusedTypeIgnorePreservedOnRerunWithIgnoredMissingImports] |
| 705 |
$ dmypy start -- --no-error-summary --ignore-missing-imports --warn-unused-ignores |
| 706 |
Daemon started |
| 707 |
$ dmypy check foo |
| 708 |
foo/main.py:3: error: Unused "type: ignore" comment [unused-ignore] |
| 709 |
== Return code: 1 |
| 710 |
$ dmypy check foo |
| 711 |
foo/main.py:3: error: Unused "type: ignore" comment [unused-ignore] |
| 712 |
== Return code: 1 |
| 713 |
|
| 714 |
[file unused/__init__.py] |
| 715 |
[file unused/submodule.py] |
| 716 |
[file foo/empty.py] |
| 717 |
[file foo/__init__.py] |
| 718 |
from foo.main import * |
| 719 |
from unused.submodule import * |
| 720 |
[file foo/main.py] |
| 721 |
from foo import empty |
| 722 |
from foo.does_not_exist import * |
| 723 |
a = 1 # type: ignore |
| 724 |
|
| 725 |
[case testModuleDoesNotExistPreservedOnRerun] |
| 726 |
$ dmypy start -- --no-error-summary --ignore-missing-imports |
| 727 |
Daemon started |
| 728 |
$ dmypy check foo |
| 729 |
foo/main.py:1: error: Module "foo" has no attribute "does_not_exist" [attr-defined] |
| 730 |
== Return code: 1 |
| 731 |
$ dmypy check foo |
| 732 |
foo/main.py:1: error: Module "foo" has no attribute "does_not_exist" [attr-defined] |
| 733 |
== Return code: 1 |
| 734 |
|
| 735 |
[file unused/__init__.py] |
| 736 |
[file unused/submodule.py] |
| 737 |
[file foo/__init__.py] |
| 738 |
from foo.main import * |
| 739 |
[file foo/main.py] |
| 740 |
from foo import does_not_exist |
| 741 |
from unused.submodule import * |
| 742 |
|
| 743 |
[case testReturnTypeIgnoreAfterUnknownImport] |
| 744 |
-- Return type ignores after unknown imports and unused modules are respected on the second pass. |
| 745 |
$ dmypy start -- --warn-unused-ignores --no-error-summary |
| 746 |
Daemon started |
| 747 |
$ dmypy check -- foo.py |
| 748 |
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] |
| 749 |
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 750 |
== Return code: 1 |
| 751 |
$ dmypy check -- foo.py |
| 752 |
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] |
| 753 |
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 754 |
== Return code: 1 |
| 755 |
|
| 756 |
[file unused/__init__.py] |
| 757 |
[file unused/empty.py] |
| 758 |
[file foo.py] |
| 759 |
from unused.empty import * |
| 760 |
import a_module_which_does_not_exist |
| 761 |
def is_foo() -> str: |
| 762 |
return True # type: ignore |
| 763 |
|
| 764 |
[case testAttrsTypeIgnoreAfterUnknownImport] |
| 765 |
$ dmypy start -- --warn-unused-ignores --no-error-summary |
| 766 |
Daemon started |
| 767 |
$ dmypy check -- foo.py |
| 768 |
foo.py:3: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] |
| 769 |
foo.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 770 |
== Return code: 1 |
| 771 |
$ dmypy check -- foo.py |
| 772 |
foo.py:3: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] |
| 773 |
foo.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports |
| 774 |
== Return code: 1 |
| 775 |
|
| 776 |
[file unused/__init__.py] |
| 777 |
[file unused/empty.py] |
| 778 |
[file foo.py] |
| 779 |
import attr |
| 780 |
from unused.empty import * |
| 781 |
import a_module_which_does_not_exist |
| 782 |
|
| 783 |
@attr.frozen |
| 784 |
class A: |
| 785 |
def __init__(self) -> None: |
| 786 |
self.__attrs_init__() # type: ignore[attr-defined] |
| 787 |
|
| 788 |
[case testDaemonImportAncestors] |
| 789 |
$ dmypy run test.py |
| 790 |
Daemon started |
| 791 |
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator] |
| 792 |
Found 1 error in 1 file (checked 1 source file) |
| 793 |
== Return code: 1 |
| 794 |
$ dmypy run test.py |
| 795 |
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator] |
| 796 |
Found 1 error in 1 file (checked 1 source file) |
| 797 |
== Return code: 1 |
| 798 |
$ dmypy run test.py |
| 799 |
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator] |
| 800 |
Found 1 error in 1 file (checked 1 source file) |
| 801 |
== Return code: 1 |
| 802 |
[file test.py] |
| 803 |
from xml.etree.ElementTree import Element |
| 804 |
1 + 'a' |