8000 Simplify default test stubs to speed up tests slightly (#8179) · python/mypy@04366e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04366e7

Browse files
authored
Simplify default test stubs to speed up tests slightly (#8179)
This speeds up the set of "quick" tests that I typically run by about 2%.
1 parent ce186f4 commit 04366e7

9 files changed

+28
-9
lines changed

test-data/unit/check-dataclasses.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Person('John', 32)
1515
Person('Jonh', 21, None) # E: Too many arguments for "Person"
1616

1717
[builtins fixtures/list.pyi]
18+
[typing fixtures/typing-full.pyi]
1819

1920
[case testDataclassesCustomInit]
2021
# flags: --python-version 3.6
@@ -52,6 +53,7 @@ Person(32, 'John')
5253
Person(21, 'Jonh', None) # E: Too many arguments for "Person"
5354

5455
[builtins fixtures/list.pyi]
56+
[typing fixtures/typing-full.pyi]
5557

5658
[case testDataclassesDeepInheritance]
5759
# flags: --python-version 3.6

test-data/unit/check-errorcodes.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ def g() -> int:
615615
'{}'.format(b'abc') # E: On Python 3 '{}'.format(b'abc') produces "b'abc'"; use !r if this is a desired behavior [str-bytes-safe]
616616
'%s' % b'abc' # E: On Python 3 '%s' % b'abc' produces "b'abc'"; use %r if this is a desired behavior [str-bytes-safe]
617617
[builtins fixtures/primitives.pyi]
618+
[typing fixtures/typing-full.pyi]
618619

619620
[case testErrorCodeIgnoreNamedDefinedNote]
620621
x: List[int] # type: ignore[name-defined]

test-data/unit/check-expressions.test

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ i, f, s, t = None, None, None, None # type: (int, float, str, Tuple[int])
11521152
'%i' % f
11531153
'%o' % f # E: Incompatible types in string interpolation (expression has type "float", placeholder has type "int")
11541154
[builtins fixtures/primitives.pyi]
1155+
[typing fixtures/typing-full.pyi]
11551156

11561157
[case testStringInterpolationSAcceptsAnyType]
11571158
from typing import Any
@@ -1179,6 +1180,7 @@ reveal_type('%(key)s' % {'key': xu}) # N: Revealed type is 'builtins.unicode'
11791180
reveal_type('%r' % xu) # N: Revealed type is 'builtins.str'
11801181
reveal_type('%s' % xs) # N: Revealed type is 'builtins.str'
11811182
[builtins fixtures/primitives.pyi]
1183+
[typing fixtures/typing-full.pyi]
11821184

11831185
[case testStringInterpolationCount]
11841186
'%d %d' % 1 # E: Not enough arguments for format string
@@ -1189,12 +1191,14 @@ t = 1, 's'
11891191
'%s %d' % t # E: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float, SupportsInt]")
11901192
'%d' % t # E: Not all arguments converted during string formatting
11911193
[builtins fixtures/primitives.pyi]
1194+
[typing fixtures/typing-full.pyi]
11921195

11931196
[case testStringInterpolationWithAnyType]
11941197
from typing import Any
11951198
a = None # type: Any
11961199
'%d %d' % a
11971200
[builtins fixtures/primitives.pyi]
1201+
[typing fixtures/typing-full.pyi]
11981202

11991203
[case testStringInterpolationInvalidPlaceholder]
12001204
'%W' % 1 # E: Unsupported format character 'W'
@@ -1221,13 +1225,15 @@ b'%a' % 3
12211225
'%*f' % (4, 3.14)
12221226
'%*f' % (1.1, 3.14) # E: * wants int
12231227
[builtins fixtures/primitives.pyi]
1228+
[typing fixtures/typing-full.pyi]
12241229

12251230
[case testStringInterpolationPrecision]
12261231
'%.2f' % 3.14
12271232
'%.*f' % 3.14 # E: Not enough arguments for format string
12281233
'%.*f' % (4, 3.14)
12291234
'%.*f' % (1.1, 3.14) # E: * wants int
12301235
[builtins fixtures/primitives.pyi]
1236+
[typing fixtures/typing-full.pyi]
12311237

12321238
[case testStringInterpolationWidthAndPrecision]
12331239
'%4.2f' % 3.14
@@ -1236,20 +1242,23 @@ b'%a' % 3
12361242
'%*.*f' % 3.14 # E: Not enough arguments for format string
12371243
'%*.*f' % (4, 2, 3.14)
12381244
[builtins fixtures/primitives.pyi]
1245+
[typing fixtures/typing-full.pyi]
12391246

12401247
[case testStringInterpolationFlagsAndLengthModifiers]
12411248
'%04hd' % 1
12421249
'%-.4ld' % 1
12431250
'%+*Ld' % (1, 1)
12441251
'% .*ld' % (1, 1)
12451252
[builtins fixtures/primitives.pyi]
1253+
[typing fixtures/typing-full.pyi]
12461254

12471255
[case testStringInterpolationDoublePercentage]
12481256
'%% %d' % 1
12491257
'%3% %d' % 1
12501258
'%*%' % 1
12511259
'%*% %d' % 1 # E: Not enough arguments for format string
12521260
[builtins fixtures/primitives.pyi]
1261+
[typing fixtures/typing-full.pyi]
12531262

12541263
[case testStringInterpolationC]
12551264
'%c' % 1
@@ -1263,14 +1272,15 @@ b'%a' % 3
12631272
'%(a)d %(b)s' % {'a': 's', 'b': 1} # E: Incompatible types in string interpolation (expression has type "str", placeholder with key 'a' has type "Union[int, float, SupportsInt]")
12641273
b'%(x)s' % {b'x': b'data'}
12651274
[builtins fixtures/primitives.pyi]
1275+
[typing fixtures/typing-full.pyi]
12661276

12671277
[case testStringInterpolationMappingKeys]
12681278
'%()d' % {'': 2}
12691279
'%(a)d' % {'a': 1, 'b': 2, 'c': 3}
12701280
'%(q)d' % {'a': 1, 'b': 2, 'c': 3} # E: Key 'q' not found in mapping
12711281
'%(a)d %%' % {'a': 1}
1272-
12731282
[builtins fixtures/primitives.pyi]
1283+
[typing fixtures/typing-full.pyi]
12741284

12751285
[case testStringInterpolationMappingDictTypes]
12761286
from typing import Any, Dict
@@ -1300,13 +1310,15 @@ di = None # type: Dict[int, int]
13001310
'%(a).1d' % {'a': 1}
13011311
'%(a)#1.1ld' % {'a': 1}
13021312
[builtins fixtures/primitives.pyi]
1313+
[typing fixtures/typing-full.pyi]
13031314

13041315
[case testStringInterpolationFloatPrecision]
13051316
'%.f' % 1.2
13061317
'%.3f' % 1.2
13071318
'%.f' % 'x'
13081319
'%.3f' % 'x'
13091320
[builtins fixtures/primitives.pyi]
1321+
[typing fixtures/typing-full.pyi]
13101322
[out]
13111323
main:3: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float, SupportsFloat]")
13121324
main:4: error: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float, SupportsFloat]")
@@ -1322,6 +1334,7 @@ foo(b'a', b'b') == b'a:b'
13221334
[case testStringInterpolationStarArgs]
13231335
x = (1, 2)
13241336
"%d%d" % (*x,)
1337+
[typing fixtures/typing-full.pyi]
13251338

13261339
[case testBytePercentInterpolationSupported]
13271340
b'%s' % (b'xyz',)
@@ -1338,6 +1351,7 @@ def f(t: Tuple[int, ...]) -> None:
13381351
'%d %d' % t
13391352
'%d %d %d' % t
13401353
[builtins fixtures/primitives.pyi]
1354+
[typing fixtures/typing-full.pyi]
13411355

13421356
[case testStringInterpolationUnionType]
13431357
from typing import Tuple, Union
@@ -1672,6 +1686,7 @@ class Good:
16721686
x: Union[float, Good]
16731687
'{:+f}'.format(x)
16741688
[builtins fixtures/primitives.pyi]
1689+
[typing fixtures/typing-full.pyi]
16751690

16761691
[case testFormatCallSpecialCases]
16771692
'{:08b}'.format(int('3'))
@@ -1683,6 +1698,7 @@ class S:
16831698
'%d' % S() # This is OK however
16841699
'{:%}'.format(0.001)
16851700
[builtins fixtures/primitives.pyi]
1701+
[typing fixtures/typing-full.pyi]
16861702

16871703
-- Lambdas
16881704
-- -------

test-data/unit/fixtures/async_await.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class object:
1212
class type: pass
1313
class function: pass
1414
class int: pass
15+
class float: pass
1516
class str: pass
1617
class bool(int): pass
1718
class dict(typing.Generic[T, U]): pass

test-data/unit/fixtures/bool.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class tuple(Generic[T]): pass
1212
class function: pass
1313
class bool: pass
1414
class int: pass
15+
class float: pass
1516
class str: pass
1617
class unicode: pass
1718
class ellipsis: pass

test-data/unit/fixtures/python2.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class type:
1111
class function: pass
1212

1313
class int: pass
14+
class float: pass
1415
class str:
1516
def format(self, *args, **kwars) -> str: ...
1617
class unicode:

test-data/unit/fixtures/typing-full.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class MutableMapping(Mapping[T, U], metaclass=ABCMeta):
140140
class SupportsInt(Protocol):
141141
def __int__(self) -> int: pass
142142

143+
class SupportsFloat(Protocol):
144+
def __float__(self) -> float: pass
145+
143146
class SupportsAbs(Protocol[T_co]):
144147
def __abs__(self) -> T_co: pass
145148

test-data/unit/lib-stub/typing.pyi

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ class Sequence(Iterable[T_co]):
3838
class Mapping(Generic[T, T_co]):
3939
def __getitem__(self, key: T) -> T_co: pass
4040

41-
class SupportsInt(Protocol):
42-
def __int__(self) -> int: pass
43-
44-
class SupportsFloat(Protocol):
45-
def __float__(self) -> float: pass
46-
47-
# This is an unofficial extension.
4841
def final(meth: T) -> T: pass
4942

5043
TYPE_CHECKING = 1

test-data/unit/typexport-basic.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,10 @@ ListExpr(3) : builtins.list[builtins.str]
11511151
OpExpr(3) : builtins.list[builtins.str]
11521152

11531153
[case testStringFormatting]
1154-
## .*
1154+
## IntExpr|OpExpr|StrExpr
11551155
'%d' % 1
11561156
[builtins fixtures/primitives.pyi]
1157+
[typing fixtures/typing-full.pyi]
11571158
[out]
11581159
IntExpr(2) : Literal[1]?
11591160
OpExpr(2) : builtins.str

0 commit comments

Comments
 (0)
0