Skip to content

Commit 475148f

Browse files
authored
Make tests use \[ to escape brackets instead of [[ (#7521)
The main motivation here (though I also just like it more) is that editor indentation modes won't get confused by unnested brackets when editing test files in python-mode, which I do all the time.
1 parent 8782ae7 commit 475148f

17 files changed

+235
-240
lines changed

mypy/test/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def parse_test_data(raw_data: str, name: str) -> List[TestItem]:
424424
while i < len(lines):
425425
s = lines[i].strip()
426426

427-
if lines[i].startswith('[') and s.endswith(']') and not s.startswith('[['):
427+
if lines[i].startswith('[') and s.endswith(']'):
428428
if id:
429429
data = collapse_line_continuation(data)
430430
data = strip_list(data)
@@ -437,7 +437,7 @@ def parse_test_data(raw_data: str, name: str) -> List[TestItem]:
437437
arg = id[id.index(' ') + 1:]
438438
id = id[:id.index(' ')]
439439
data = []
440-
elif lines[i].startswith('[['):
440+
elif lines[i].startswith('\\['):
441441
data.append(lines[i][1:])
442442
elif not lines[i].startswith('--'):
443443
data.append(lines[i])

mypyc/test-data/run.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ from native import primes
418418
print(primes(3))
419419
print(primes(13))
420420
[out]
421-
[[0, 0, 1, 1]
422-
[[0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1]
423-
-- argh ]]
421+
\[0, 0, 1, 1]
422+
\[0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1]
424423

425424

426425
[case testListPrims]

test-data/unit/check-custom-plugin.test

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
def f() -> str: ...
99
reveal_type(f()) # N: Revealed type is 'builtins.int'
1010
[file mypy.ini]
11-
[[mypy]
11+
\[mypy]
1212
plugins=<ROOT>/test-data/unit/plugins/fnplugin.py
1313

1414
[case testFunctionPlugin]
1515
# flags: --config-file tmp/mypy.ini
1616
def f() -> str: ...
1717
reveal_type(f()) # N: Revealed type is 'builtins.int'
1818
[file mypy.ini]
19-
[[mypy]
19+
\[mypy]
2020
plugins=fnplugin
2121

2222
[case testFunctionPluginFullnameIsNotNone]
@@ -27,7 +27,7 @@ T = TypeVar('T')
2727
def g(x: T) -> T: return x # This strips out the name of a callable
2828
g(f)()
2929
[file mypy.ini]
30-
[[mypy]
30+
\[mypy]
3131
plugins=<ROOT>/test-data/unit/plugins/fnplugin.py
3232

3333
[case testTwoPlugins]
@@ -39,7 +39,7 @@ reveal_type(f()) # N: Revealed type is 'builtins.int'
3939
reveal_type(g()) # N: Revealed type is 'builtins.str'
4040
reveal_type(h()) # N: Revealed type is 'Any'
4141
[file mypy.ini]
42-
[[mypy]
42+
\[mypy]
4343
plugins=<ROOT>/test-data/unit/plugins/fnplugin.py,
4444
<ROOT>/test-data/unit/plugins/plugin2.py
4545

@@ -52,13 +52,13 @@ reveal_type(f()) # N: Revealed type is 'builtins.int'
5252
reveal_type(g()) # N: Revealed type is 'builtins.str'
5353
reveal_type(h()) # N: Revealed type is 'Any'
5454
[file mypy.ini]
55-
[[mypy]
55+
\[mypy]
5656
plugins=<ROOT>/test-data/unit/plugins/fnplugin.py, plugin2
5757

5858
[case testMissingPluginFile]
5959
# flags: --config-file tmp/mypy.ini
6060
[file mypy.ini]
61-
[[mypy]
61+
\[mypy]
6262
plugins=missing.py
6363
[out]
6464
tmp/mypy.ini:2: error: Can't find plugin 'tmp/missing.py'
@@ -67,19 +67,19 @@ tmp/mypy.ini:2: error: Can't find plugin 'tmp/missing.py'
6767
[case testMissingPlugin]
6868
# flags: --config-file tmp/mypy.ini
6969
[file mypy.ini]
70-
[[mypy]
70+
\[mypy]
7171
plugins=missing
7272
[out]
7373
tmp/mypy.ini:2: error: Error importing plugin 'missing'
7474

7575
[case testMultipleSectionsDefinePlugin]
7676
# flags: --config-file tmp/mypy.ini
7777
[file mypy.ini]
78-
[[acme]
78+
\[acme]
7979
plugins=acmeplugin
80-
[[mypy]
80+
\[mypy]
8181
plugins=missing.py
82-
[[another]
82+
\[another]
8383
plugins=another_plugin
8484
[out]
8585
tmp/mypy.ini:4: error: Can't find plugin 'tmp/missing.py'
@@ -88,7 +88,7 @@ tmp/mypy.ini:4: error: Can't find plugin 'tmp/missing.py'
8888
[case testInvalidPluginExtension]
8989
# flags: --config-file tmp/mypy.ini
9090
[file mypy.ini]
91-
[[mypy]
91+
\[mypy]
9292
plugins=dir/badext.pyi
9393
[file dir/badext.pyi]
9494
[out]
@@ -97,7 +97,7 @@ tmp/mypy.ini:2: error: Plugin 'badext.pyi' does not have a .py extension
9797
[case testMissingPluginEntryPoint]
9898
# flags: --config-file tmp/mypy.ini
9999
[file mypy.ini]
100-
[[mypy]
100+
\[mypy]
101101
plugins = <ROOT>/test-data/unit/plugins/noentry.py
102102
[out]
103103
tmp/mypy.ini:2: error: Plugin '<ROOT>/test-data/unit/plugins/noentry.py' does not define entry point function "plugin"
@@ -107,23 +107,23 @@ tmp/mypy.ini:2: error: Plugin '<ROOT>/test-data/unit/plugins/noentry.py' does no
107107
def f() -> str: ...
108108
reveal_type(f()) # N: Revealed type is 'builtins.int'
109109
[file mypy.ini]
110-
[[mypy]
110+
\[mypy]
111111
plugins=<ROOT>/test-data/unit/plugins/customentry.py:register
112112

113113
[case testCustomPluginEntryPoint]
114114
# flags: --config-file tmp/mypy.ini
115115
def f() -> str: ...
116116
reveal_type(f()) # N: Revealed type is 'builtins.int'
117117
[file mypy.ini]
118-
[[mypy]
118+
\[mypy]
119119
plugins=customentry:register
120120

121121
[case testInvalidPluginEntryPointReturnValue]
122122
# flags: --config-file tmp/mypy.ini
123123
def f(): pass
124124
f()
125125
[file mypy.ini]
126-
[[mypy]
126+
\[mypy]
127127

128128
plugins=<ROOT>/test-data/unit/plugins/badreturn.py
129129
[out]
@@ -134,7 +134,7 @@ tmp/mypy.ini:3: error: Type object expected as the return value of "plugin"; got
134134
def f(): pass
135135
f()
136136
[file mypy.ini]
137-
[[mypy]
137+
\[mypy]
138138
plugins=<ROOT>/test-data/unit/plugins/badreturn2.py
139139
[out]
140140
tmp/mypy.ini:2: error: Return value of "plugin" must be a subclass of "mypy.plugin.Plugin" (in <ROOT>/test-data/unit/plugins/badreturn2.py)
@@ -157,7 +157,7 @@ class Signal(Generic[T]):
157157

158158
class DerivedSignal(Signal[T]): ...
159159
[file mypy.ini]
160-
[[mypy]
160+
\[mypy]
161161
plugins=<ROOT>/test-data/unit/plugins/attrhook.py
162162

163163
[case testAttributeHookPluginForDynamicClass]
@@ -182,7 +182,7 @@ class Magic:
182182
class DerivedMagic(Magic): ...
183183

184184
[file mypy.ini]
185-
[[mypy]
185+
\[mypy]
186186
plugins=<ROOT>/test-data/unit/plugins/attrhook2.py
187187

188188
[case testTypeAnalyzeHookPlugin]
@@ -200,7 +200,7 @@ T = TypeVar('T', bound=Callable[..., None])
200200
class Signal(Generic[T]):
201201
__call__: Callable[..., None]
202202
[file mypy.ini]
203-
[[mypy]
203+
\[mypy]
204204
plugins=<ROOT>/test-data/unit/plugins/type_anal_hook.py
205205
[builtins fixtures/dict.pyi]
206206

@@ -237,7 +237,7 @@ class AttrInt(Attr[int]):
237237
pass
238238

239239
[file mypy.ini]
240-
[[mypy]
240+
\[mypy]
241241
plugins=<ROOT>/test-data/unit/plugins/class_callable.py
242242
[builtins fixtures/bool.pyi]
243243
[out]
@@ -256,7 +256,7 @@ from typing import Callable
256256
def decorator1() -> Callable[..., Callable[..., int]]: pass
257257
def decorator2() -> Callable[..., Callable[..., int]]: pass
258258
[file mypy.ini]
259-
[[mypy]
259+
\[mypy]
260260
plugins=<ROOT>/test-data/unit/plugins/named_callable.py
261261

262262
[case testFunctionMethodContextsHasArgNames]
@@ -284,7 +284,7 @@ def func(classname: str, arg1: Any, arg2: Any) -> Any:
284284
pass
285285

286286
[file mypy.ini]
287-
[[mypy]
287+
\[mypy]
288288
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
289289
[builtins fixtures/classmethod.pyi]
290290

@@ -313,7 +313,7 @@ def func(classname: str, arg1: Any, arg2: Any) -> Any:
313313
pass
314314

315315
[file mypy.ini]
316-
[[mypy]
316+
\[mypy]
317317
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
318318
[builtins fixtures/classmethod.pyi]
319319

@@ -335,7 +335,7 @@ class Outer:
335335
pass
336336

337337
[file mypy.ini]
338-
[[mypy]
338+
\[mypy]
339339
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
340340

341341
[case testFunctionMethodContextsHasArgNamesUnfilledArguments]
@@ -358,7 +358,7 @@ def func_unfilled(classname: str, arg1: Any = None, arg2: Any = None) -> Any:
358358
pass
359359

360360
[file mypy.ini]
361-
[[mypy]
361+
\[mypy]
362362
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
363363

364364
[case testFunctionMethodContextsHasArgNamesStarExpressions]
@@ -382,7 +382,7 @@ def func_star_expr(classname: str, *args, **kwargs) -> Any:
382382
pass
383383

384384
[file mypy.ini]
385-
[[mypy]
385+
\[mypy]
386386
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
387387
[builtins fixtures/dict.pyi]
388388

@@ -406,7 +406,7 @@ class ClassChild(Base):
406406
pass
407407

408408
[file mypy.ini]
409-
[[mypy]
409+
\[mypy]
410410
plugins=<ROOT>/test-data/unit/plugins/arg_names.py
411411
[builtins fixtures/classmethod.pyi]
412412

@@ -435,7 +435,7 @@ for x in foo:
435435
reveal_type(x) # N: Revealed type is 'builtins.int*'
436436

437437
[file mypy.ini]
438-
[[mypy]
438+
\[mypy]
439439
plugins=<ROOT>/test-data/unit/plugins/method_sig_hook.py
440440

441441
[case testMethodSignatureHookNamesFullyQualified]
@@ -459,7 +459,7 @@ reveal_type(FullyQualifiedTestClass().instance_method()) # N: Revealed type is '
459459
reveal_type(FullyQualifiedTestNamedTuple('')._asdict()) # N: Revealed type is 'builtins.int'
460460

461461
[file mypy.ini]
462-
[[mypy]
462+
\[mypy]
463463
plugins=<ROOT>/test-data/unit/plugins/fully_qualified_test_hook.py
464464
[builtins fixtures/classmethod.pyi]
465465

@@ -486,7 +486,7 @@ class Column(Generic[T]): ...
486486
class Instr(Generic[T]): ...
487487

488488
[file mypy.ini]
489-
[[mypy]
489+
\[mypy]
490490
plugins=<ROOT>/test-data/unit/plugins/dyn_class.py
491491

492492
[case testDynamicClassPluginNegatives]
@@ -513,7 +513,7 @@ class Column(Generic[T]): ...
513513
class Instr(Generic[T]): ...
514514

515515
[file mypy.ini]
516-
[[mypy]
516+
\[mypy]
517517
plugins=<ROOT>/test-data/unit/plugins/dyn_class.py
518518

519519
[case testBaseClassPluginHookWorksIncremental]
@@ -539,7 +539,7 @@ from typing import Any
539539
def declarative_base() -> Any: ...
540540

541541
[file mypy.ini]
542-
[[mypy]
542+
\[mypy]
543543
python_version=3.6
544544
plugins=<ROOT>/test-data/unit/plugins/common_api_incremental.py
545545
[out]
@@ -556,7 +556,7 @@ class Class:
556556
Class().method(1, *[2], **{'a': 1}) # E: [[0, 2], [4]]
557557
[builtins fixtures/dict.pyi]
558558
[file mypy.ini]
559-
[[mypy]
559+
\[mypy]
560560
plugins=<ROOT>/test-data/unit/plugins/arg_kinds.py
561561

562562
[case testArgKindsFunction]
@@ -567,7 +567,7 @@ def func(*args, **kwargs):
567567
func(1, 2, [3, 4], *[5, 6, 7], **{'a': 1}) # E: [[0, 0, 0, 2], [4]]
568568
[builtins fixtures/dict.pyi]
569569
[file mypy.ini]
570-
[[mypy]
570+
\[mypy]
571571
plugins=<ROOT>/test-data/unit/plugins/arg_kinds.py
572572

573573
[case testHookCallableInstance]
@@ -582,7 +582,7 @@ instance = Class(3.14)
582582
reveal_type(instance(2)) # N: Revealed type is 'builtins.float*'
583583

584584
[file mypy.ini]
585-
[[mypy]
585+
\[mypy]
586586
plugins=<ROOT>/test-data/unit/plugins/callable_instance.py
587587

588588
[case testGetMethodHooksOnUnions]
@@ -604,7 +604,7 @@ else:
604604

605605
[builtins fixtures/isinstancelist.pyi]
606606
[file mypy.ini]
607-
[[mypy]
607+
\[mypy]
608608
plugins=<ROOT>/test-data/unit/plugins/union_method.py
609609

610610
[case testGetMethodHooksOnUnionsStrictOptional]
@@ -626,7 +626,7 @@ else:
626626

627627
[builtins fixtures/isinstancelist.pyi]
628628
[file mypy.ini]
629-
[[mypy]
629+
\[mypy]
630630
plugins=<ROOT>/test-data/unit/plugins/union_method.py
631631

632632
[case testGetMethodHooksOnUnionsSpecial]
@@ -643,7 +643,7 @@ reveal_type(x[int()]) # N: Revealed type is 'builtins.int'
643643

644644
[builtins fixtures/isinstancelist.pyi]
645645
[file mypy.ini]
646-
[[mypy]
646+
\[mypy]
647647
plugins=<ROOT>/test-data/unit/plugins/union_method.py
648648

649649
[case testPluginDependencies]
@@ -656,12 +656,12 @@ plugins=<ROOT>/test-data/unit/plugins/union_method.py
656656
1 + 'lol' # E: Unsupported operand types for + ("int" and "str")
657657

658658
[file mypy.ini]
659-
[[mypy]
659+
\[mypy]
660660
plugins=<ROOT>/test-data/unit/plugins/depshook.py
661661

662662
[case testCustomizeMroTrivial]
663663
# flags: --config-file tmp/mypy.ini
664664
class A: pass
665665
[file mypy.ini]
666-
[[mypy]
666+
\[mypy]
667667
plugins=<ROOT>/test-data/unit/plugins/customize_mro.py

0 commit comments

Comments
 (0)