| 1 |
[case testReportBasic] |
| 2 |
# flags: --xml-report out |
| 3 |
def f(): pass |
| 4 |
|
| 5 |
def g() -> None: pass |
| 6 |
[outfile out/index.xml] |
| 7 |
<?xml-stylesheet type="text/xsl" href="mypy-html.xslt"?><mypy-report-index name="index"><file module="__main__" name="main" total="4" any="1" empty="2" imprecise="0" precise="1" unanalyzed="0"/></mypy-report-index> |
| 8 |
|
| 9 |
[case testLinePrecisionBasic] |
| 10 |
# flags: --lineprecision-report out |
| 11 |
def f(): pass |
| 12 |
|
| 13 |
def g() -> None: |
| 14 |
a = 1 |
| 15 |
[outfile out/lineprecision.txt] |
| 16 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 17 |
------------------------------------------------------------- |
| 18 |
__main__ 5 2 0 1 2 0 |
| 19 |
|
| 20 |
[case testLinePrecisionImpreciseType] |
| 21 |
# flags: --lineprecision-report out |
| 22 |
def f(x: list) -> None: pass |
| 23 |
[builtins fixtures/list.pyi] |
| 24 |
[outfile out/lineprecision.txt] |
| 25 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 26 |
------------------------------------------------------------- |
| 27 |
__main__ 2 0 1 0 1 0 |
| 28 |
|
| 29 |
[case testLinePrecisionUnanalyzed] |
| 30 |
# flags: --lineprecision-report out |
| 31 |
import sys |
| 32 |
MYPY = False |
| 33 |
if not MYPY: |
| 34 |
a = 1 |
| 35 |
|
| 36 |
def f(x: int) -> None: |
| 37 |
if isinstance(x, str): |
| 38 |
b = 1 |
| 39 |
c = 1 |
| 40 |
[builtins fixtures/isinstance.pyi] |
| 41 |
[outfile out/lineprecision.txt] |
| 42 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 43 |
------------------------------------------------------------- |
| 44 |
__main__ 10 5 0 0 2 3 |
| 45 |
|
| 46 |
[case testLinePrecisionEmptyLines] |
| 47 |
# flags: --lineprecision-report out |
| 48 |
def f() -> None: |
| 49 |
"""docstring |
| 50 |
|
| 51 |
long |
| 52 |
""" |
| 53 |
x = 0 |
| 54 |
|
| 55 |
# comment |
| 56 |
y = 0 # comment (non-empty) |
| 57 |
[outfile out/lineprecision.txt] |
| 58 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 59 |
------------------------------------------------------------- |
| 60 |
__main__ 10 3 0 0 7 0 |
| 61 |
|
| 62 |
[case testLinePrecisionImportFrom] |
| 63 |
# flags: --lineprecision-report out --ignore-missing-imports |
| 64 |
from m import f |
| 65 |
from m import g |
| 66 |
from bad import foo |
| 67 |
from bad import ( # treated as a single line |
| 68 |
foo2, |
| 69 |
foo3, |
| 70 |
) |
| 71 |
|
| 72 |
[file m.py] |
| 73 |
def f(): pass |
| 74 |
def g() -> None: pass |
| 75 |
|
| 76 |
[outfile out/lineprecision.txt] |
| 77 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 78 |
------------------------------------------------------------- |
| 79 |
__main__ 8 2 0 2 4 0 |
| 80 |
m 2 1 0 1 0 0 |
| 81 |
|
| 82 |
[case testLinePrecisionImport] |
| 83 |
# flags: --lineprecision-report out --ignore-missing-imports |
| 84 |
import m |
| 85 |
import bad |
| 86 |
import m, bad |
| 87 |
|
| 88 |
[file m.py] |
| 89 |
[outfile out/lineprecision.txt] |
| 90 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 91 |
------------------------------------------------------------- |
| 92 |
__main__ 4 1 0 2 1 0 |
| 93 |
m 0 0 0 0 0 0 |
| 94 |
|
| 95 |
[case testLinePrecisionStarImport] |
| 96 |
# flags: --lineprecision-report out --ignore-missing-imports |
| 97 |
from m import * |
| 98 |
from bad import * |
| 99 |
|
| 100 |
[file m.py] |
| 101 |
def f(): pass |
| 102 |
def g() -> None: pass |
| 103 |
[outfile out/lineprecision.txt] |
| 104 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 105 |
------------------------------------------------------------- |
| 106 |
__main__ 3 1 0 1 1 0 |
| 107 |
m 2 1 0 1 0 0 |
| 108 |
|
| 109 |
[case testLinePrecisionRelativeImport] |
| 110 |
# flags: --lineprecision-report out --ignore-missing-imports |
| 111 |
import a |
| 112 |
|
| 113 |
[file a/__init__.py] |
| 114 |
from .m import f |
| 115 |
from .bad import g |
| 116 |
|
| 117 |
[file a/m.py] |
| 118 |
def f(): pass |
| 119 |
|
| 120 |
[outfile out/lineprecision.txt] |
| 121 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 122 |
------------------------------------------------------------- |
| 123 |
__main__ 2 1 0 0 1 0 |
| 124 |
a 2 1 0 1 0 0 |
| 125 |
a.m 1 0 0 1 0 0 |
| 126 |
|
| 127 |
[case testLinePrecisionPassStatement] |
| 128 |
# flags: --lineprecision-report out |
| 129 |
def f() -> None: |
| 130 |
pass |
| 131 |
def g(): |
| 132 |
pass |
| 133 |
class C: |
| 134 |
pass |
| 135 |
[outfile out/lineprecision.txt] |
| 136 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 137 |
------------------------------------------------------------- |
| 138 |
__main__ 7 4 0 2 1 0 |
| 139 |
|
| 140 |
[case testLinePrecisionBreakAndContinueStatement] |
| 141 |
# flags: --lineprecision-report out |
| 142 |
import a |
| 143 |
import b |
| 144 |
|
| 145 |
[file a.py] |
| 146 |
def f() -> int: |
| 147 |
while f(): |
| 148 |
break |
| 149 |
return f() |
| 150 |
def g(): |
| 151 |
while g(): |
| 152 |
break |
| 153 |
|
| 154 |
[file b.py] |
| 155 |
def f() -> int: |
| 156 |
while f(): |
| 157 |
continue |
| 158 |
return f() |
| 159 |
def g(): |
| 160 |
while g(): |
| 161 |
continue |
| 162 |
|
| 163 |
[outfile out/lineprecision.txt] |
| 164 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 165 |
------------------------------------------------------------- |
| 166 |
__main__ 3 2 0 0 1 0 |
| 167 |
a 7 4 0 3 0 0 |
| 168 |
b 7 4 0 3 0 0 |
| 169 |
|
| 170 |
[case testLinePrecisionLiterals] |
| 171 |
# flags: --lineprecision-report out |
| 172 |
import str_lit |
| 173 |
import bytes_lit |
| 174 |
import int_lit |
| 175 |
import float_lit |
| 176 |
import true_lit |
| 177 |
import false_lit |
| 178 |
import none_lit |
| 179 |
import complex_lit |
| 180 |
import dots_lit |
| 181 |
|
| 182 |
[file str_lit.py] |
| 183 |
def f() -> object: |
| 184 |
return '' |
| 185 |
def g(): |
| 186 |
return '' |
| 187 |
|
| 188 |
[file bytes_lit.py] |
| 189 |
def f() -> object: |
| 190 |
return b'' |
| 191 |
def g(): |
| 192 |
return b'' |
| 193 |
|
| 194 |
[file int_lit.py] |
| 195 |
def f() -> object: |
| 196 |
return 1 |
| 197 |
def g(): |
| 198 |
return 1 |
| 199 |
|
| 200 |
[file float_lit.py] |
| 201 |
def f() -> object: |
| 202 |
return 1.1 |
| 203 |
def g(): |
| 204 |
return 1.1 |
| 205 |
|
| 206 |
[file true_lit.py] |
| 207 |
def f() -> object: |
| 208 |
return True |
| 209 |
def g(): |
| 210 |
return True |
| 211 |
|
| 212 |
[file false_lit.py] |
| 213 |
def f() -> object: |
| 214 |
return False |
| 215 |
def g(): |
| 216 |
return False |
| 217 |
|
| 218 |
[file none_lit.py] |
| 219 |
def f() -> object: |
| 220 |
return None |
| 221 |
def g(): |
| 222 |
return None |
| 223 |
|
| 224 |
[file complex_lit.py] |
| 225 |
def f() -> object: |
| 226 |
return None |
| 227 |
def g(): |
| 228 |
return None |
| 229 |
|
| 230 |
[file dots_lit.py] |
| 231 |
def f() -> object: |
| 232 |
return ... |
| 233 |
def g(): |
| 234 |
return ... |
| 235 |
|
| 236 |
[outfile out/lineprecision.txt] |
| 237 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 238 |
---------------------------------------------------------------- |
| 239 |
__main__ 10 9 0 0 1 0 |
| 240 |
bytes_lit 4 2 0 2 0 0 |
| 241 |
complex_lit 4 2 0 2 0 0 |
| 242 |
dots_lit 4 2 0 2 0 0 |
| 243 |
false_lit 4 2 0 2 0 0 |
| 244 |
float_lit 4 2 0 2 0 0 |
| 245 |
int_lit 4 2 0 2 0 0 |
| 246 |
none_lit 4 2 0 2 0 0 |
| 247 |
str_lit 4 2 0 2 0 0 |
| 248 |
true_lit 4 2 0 2 0 0 |
| 249 |
|
| 250 |
[case testLinePrecisionIfStatement] |
| 251 |
# flags: --lineprecision-report out |
| 252 |
if int(): |
| 253 |
x = 1 |
| 254 |
else: # This is treated as empty |
| 255 |
x = 2 |
| 256 |
[outfile out/lineprecision.txt] |
| 257 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 258 |
------------------------------------------------------------- |
| 259 |
__main__ 5 3 0 0 2 0 |
| 260 |
|
| 261 |
[case testLinePrecisionCallAnyArg] |
| 262 |
# flags: --lineprecision-report out |
| 263 |
from m import f |
| 264 |
def g() -> None: |
| 265 |
f(1) # Precise |
| 266 |
f(1, 2) # Any |
| 267 |
[file m.py] |
| 268 |
from typing import Any |
| 269 |
def f(x: int, y: Any = 0) -> None: |
| 270 |
pass |
| 271 |
[outfile out/lineprecision.txt] |
| 272 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 273 |
------------------------------------------------------------- |
| 274 |
__main__ 5 3 0 1 1 0 |
| 275 |
m 3 2 0 1 0 0 |
| 276 |
|
| 277 |
[case testLinePrecisionCallImpreciseArg] |
| 278 |
# flags: --lineprecision-report out |
| 279 |
from m import f |
| 280 |
def g() -> None: |
| 281 |
f(1) # Precise |
| 282 |
f(1, [2]) # Imprecise |
| 283 |
[file m.py] |
| 284 |
from typing import List, Any |
| 285 |
def f(x: int, y: List[Any] = []) -> None: |
| 286 |
pass |
| 287 |
[builtins fixtures/list.pyi] |
| 288 |
[outfile out/lineprecision.txt] |
| 289 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 290 |
------------------------------------------------------------- |
| 291 |
__main__ 5 3 1 0 1 0 |
| 292 |
m 3 2 1 0 0 0 |
| 293 |
|
| 294 |
[case testLinePrecisionCallAnyArgWithKeywords] |
| 295 |
# flags: --lineprecision-report out |
| 296 |
from m import f |
| 297 |
def g() -> None: |
| 298 |
f(x=1) # Precise |
| 299 |
f(x=1, z=1) # Precise |
| 300 |
f(z=1, x=1) # Precise |
| 301 |
f(y=1) # Any |
| 302 |
f(y=1, x=1) # Any |
| 303 |
[file m.py] |
| 304 |
from typing import Any |
| 305 |
def f(x: int = 0, y: Any = 0, z: int = 0) -> None: |
| 306 |
pass |
| 307 |
[outfile out/lineprecision.txt] |
| 308 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 309 |
------------------------------------------------------------- |
| 310 |
__main__ 8 5 0 2 1 0 |
| 311 |
m 3 2 0 1 0 0 |
| 312 |
|
| 313 |
[case testLinePrecisionCallAnyMethodArg] |
| 314 |
# flags: --lineprecision-report out |
| 315 |
from m import C |
| 316 |
def g(c: C) -> None: |
| 317 |
c.f(1) # Precise |
| 318 |
c.f(1, 2) # Any |
| 319 |
[file m.py] |
| 320 |
from typing import Any |
| 321 |
class C: |
| 322 |
def f(self, x: int, y: Any = 0) -> None: |
| 323 |
pass |
| 324 |
[outfile out/lineprecision.txt] |
| 325 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 326 |
------------------------------------------------------------- |
| 327 |
__main__ 5 3 0 1 1 0 |
| 328 |
m 4 3 0 1 0 0 |
| 329 |
|
| 330 |
[case testLinePrecisionCallAnyConstructorArg] |
| 331 |
# flags: --lineprecision-report out |
| 332 |
from m import C |
| 333 |
def g() -> None: |
| 334 |
C(1) # Precise |
| 335 |
C(1, 2) # Any |
| 336 |
[file m.py] |
| 337 |
from typing import Any |
| 338 |
class C: |
| 339 |
def __init__(self, x: int, y: Any = 0) -> None: |
| 340 |
pass |
| 341 |
[outfile out/lineprecision.txt] |
| 342 |
Name Lines Precise Imprecise Any Empty Unanalyzed |
| 343 |
------------------------------------------------------------- |
| 344 |
__main__ 5 3 0 1 1 0 |
| 345 |
m 4 3 0 1 0 0 |