Skip to content

Commit 409d294

Browse files
authored
Remove force_uppercase_builtins default from test helpers (#19173)
Mypy only supports Python 3.9+. Update the tests to use lowercase names for PEP 585 generics in error messages. A followup can consider deprecating `--force-uppercase-builtins` and making it a no-op.
1 parent 95a09c8 commit 409d294

File tree

88 files changed

+1617
-1632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1617
-1632
lines changed

mypy/test/helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,12 @@ def local_sys_path_set() -> Iterator[None]:
258258

259259

260260
def testfile_pyversion(path: str) -> tuple[int, int]:
261-
m = re.search(r"python3([0-9]+)\.test$", path)
262-
if m:
263-
return 3, int(m.group(1))
261+
if m := re.search(r"python3([0-9]+)\.test$", path):
262+
# For older unsupported version like python38,
263+
# default to that earliest supported version.
264+
return max((3, int(m.group(1))), defaults.PYTHON3_VERSION_MIN)
264265
else:
265-
return defaults.PYTHON3_VERSION
266+
return defaults.PYTHON3_VERSION_MIN
266267

267268

268269
def normalize_error_messages(messages: list[str]) -> list[str]:
@@ -353,7 +354,6 @@ def parse_options(
353354
options = Options()
354355
options.error_summary = False
355356
options.hide_error_codes = True
356-
options.force_uppercase_builtins = True
357357
options.force_union_syntax = True
358358

359359
# Allow custom python version to override testfile_pyversion.

mypy/test/testcheck.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ def run_case_once(
136136
options.hide_error_codes = False
137137
if "abstract" not in testcase.file:
138138
options.allow_empty_bodies = not testcase.name.endswith("_no_empty")
139-
if "lowercase" not in testcase.file:
140-
options.force_uppercase_builtins = True
141139
if "union-error" not in testcase.file:
142140
options.force_union_syntax = True
143141

mypy/test/testcmdline.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
6161
args.append("--hide-error-codes")
6262
if "--disallow-empty-bodies" not in args:
6363
args.append("--allow-empty-bodies")
64-
if "--no-force-uppercase-builtins" not in args:
65-
args.append("--force-uppercase-builtins")
6664
if "--no-force-union-syntax" not in args:
6765
args.append("--force-union-syntax")
6866
# Type check the program.

mypy/test/testmerge.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def build(self, source: str, testcase: DataDrivenTestCase) -> BuildResult | None
102102
options.export_types = True
103103
options.show_traceback = True
104104
options.allow_empty_bodies = True
105-
options.force_uppercase_builtins = True
106105
main_path = os.path.join(test_temp_dir, "main")
107106

108107
self.str_conv.options = options

mypy/test/testparse.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_parser(testcase: DataDrivenTestCase) -> None:
3838
The argument contains the description of the test case.
3939
"""
4040
options = Options()
41-
options.force_uppercase_builtins = True
4241
options.hide_error_codes = True
4342

4443
if testcase.file.endswith("python310.test"):

mypy/test/testpythoneval.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
5252
"--no-error-summary",
5353
"--hide-error-codes",
5454
"--allow-empty-bodies",
55-
"--force-uppercase-builtins",
5655
"--test-env", # Speeds up some checks
5756
]
5857
interpreter = python3_path

mypy/test/testsemanal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Opti
4444
options.semantic_analysis_only = True
4545
options.show_traceback = True
4646
options.python_version = PYTHON3_VERSION
47-
options.force_uppercase_builtins = True
4847
return options
4948

5049

mypy/test/testtransform.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_transform(testcase: DataDrivenTestCase) -> None:
3838
options.use_builtins_fixtures = True
3939
options.semantic_analysis_only = True
4040
options.show_traceback = True
41-
options.force_uppercase_builtins = True
4241
result = build.build(
4342
sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir
4443
)

mypy/test/testtypegen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
3535
options.export_types = True
3636
options.preserve_asts = True
3737
options.allow_empty_bodies = True
38-
options.force_uppercase_builtins = True
3938
result = build.build(
4039
sources=[BuildSource("main", None, src)],
4140
options=options,

mypy/test/testtypes.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Expression,
2424
NameExpr,
2525
)
26-
from mypy.options import Options
2726
from mypy.plugins.common import find_shallow_matching_overload_item
2827
from mypy.state import state
2928
from mypy.subtypes import is_more_precise, is_proper_subtype, is_same_type, is_subtype
@@ -130,17 +129,13 @@ def test_callable_type_with_var_args(self) -> None:
130129
)
131130
assert_equal(str(c3), "def (X? =, *Y?) -> Any")
132131

133-
def test_tuple_type_upper(self) -> None:
134-
options = Options()
135-
options.force_uppercase_builtins = True
136-
assert_equal(TupleType([], self.fx.std_tuple).str_with_options(options), "Tuple[()]")
137-
assert_equal(TupleType([self.x], self.fx.std_tuple).str_with_options(options), "Tuple[X?]")
138-
assert_equal(
139-
TupleType(
140-
[self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple
141-
).str_with_options(options),
142-
"Tuple[X?, Any]",
143-
)
132+
def test_tuple_type_str(self) -> None:
133+
t1 = TupleType([], self.fx.std_tuple)
134+
assert_equal(str(t1), "tuple[()]")
135+
t2 = TupleType([self.x], self.fx.std_tuple)
136+
assert_equal(str(t2), "tuple[X?]")
137+
t3 = TupleType([self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple)
138+
assert_equal(str(t3), "tuple[X?, Any]")
144139

145140
def test_type_variable_binding(self) -> None:
146141
assert_equal(

test-data/unit/check-abstract.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ def f(cls: Type[A]) -> A:
191191
def g() -> A:
192192
return A() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
193193

194-
f(A) # E: Only concrete class can be given where "Type[A]" is expected
195-
f(B) # E: Only concrete class can be given where "Type[A]" is expected
194+
f(A) # E: Only concrete class can be given where "type[A]" is expected
195+
f(B) # E: Only concrete class can be given where "type[A]" is expected
196196
f(C) # OK
197197
x: Type[B]
198198
f(x) # OK
@@ -207,7 +207,7 @@ class Class:
207207
def method(self) -> None:
208208
pass
209209

210-
my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "Tuple[int, Type[Class]]" is expected
210+
my_dict_init: Dict[int, Type[Class]] = {0: Class} # E: Only concrete class can be given where "tuple[int, type[Class]]" is expected
211211

212212
class Child(Class):
213213
def method(self) -> None: ...
@@ -235,7 +235,7 @@ Alias = A
235235
GoodAlias = C
236236
Alias() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
237237
GoodAlias()
238-
f(Alias) # E: Only concrete class can be given where "Type[A]" is expected
238+
f(Alias) # E: Only concrete class can be given where "type[A]" is expected
239239
f(GoodAlias)
240240
[out]
241241

@@ -255,18 +255,18 @@ class C(B):
255255
var: Type[A]
256256
var()
257257
if int():
258-
var = A # E: Can only assign concrete classes to a variable of type "Type[A]"
258+
var = A # E: Can only assign concrete classes to a variable of type "type[A]"
259259
if int():
260-
var = B # E: Can only assign concrete classes to a variable of type "Type[A]"
260+
var = B # E: Can only assign concrete classes to a variable of type "type[A]"
261261
if int():
262262
var = C # OK
263263

264264
var_old = None # type: Type[A] # Old syntax for variable annotations
265265
var_old()
266266
if int():
267-
var_old = A # E: Can only assign concrete classes to a variable of type "Type[A]"
267+
var_old = A # E: Can only assign concrete classes to a variable of type "type[A]"
268268
if int():
269-
var_old = B # E: Can only assign concrete classes to a variable of type "Type[A]"
269+
var_old = B # E: Can only assign concrete classes to a variable of type "type[A]"
270270
if int():
271271
var_old = C # OK
272272

@@ -277,7 +277,7 @@ class D(A):
277277
def __new__(cls) -> "D": ...
278278
def __new__(cls, a=None) -> "D": ...
279279
if int():
280-
var = D # E: Can only assign concrete classes to a variable of type "Type[A]"
280+
var = D # E: Can only assign concrete classes to a variable of type "type[A]"
281281
[out]
282282

283283
[case testInstantiationAbstractsInTypeForClassMethods]

test-data/unit/check-annotated.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ from typing_extensions import Annotated
105105
T = TypeVar('T')
106106
Alias = Annotated[Tuple[T, T], ...]
107107
x: Alias[int]
108-
reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]"
108+
reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]"
109109
[builtins fixtures/tuple.pyi]
110110

111111
[case testAnnotatedAliasGenericUnion]

test-data/unit/check-async-await.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def f() -> None:
163163
[builtins fixtures/async_await.pyi]
164164
[typing fixtures/typing-async.pyi]
165165
[out]
166-
main:4: error: "List[int]" has no attribute "__aiter__" (not async iterable)
166+
main:4: error: "list[int]" has no attribute "__aiter__" (not async iterable)
167167

168168
[case testAsyncForErrorNote]
169169

@@ -502,7 +502,7 @@ async def gen() -> AsyncGenerator[int, str]:
502502

503503
async def h() -> None:
504504
g = gen()
505-
await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "Tuple[()]"; expected "str"
505+
await g.asend(()) # E: Argument 1 to "asend" of "AsyncGenerator" has incompatible type "tuple[()]"; expected "str"
506506
reveal_type(await g.asend('hello')) # N: Revealed type is "builtins.int"
507507

508508
[builtins fixtures/dict.pyi]
@@ -913,9 +913,9 @@ async def test(x: Sub[D], tx: Type[Sub[D]]) -> None:
913913
unknown2: Awaitable[Any]
914914
d: C = unknown2 # E: Incompatible types in assignment (expression has type "Awaitable[Any]", variable has type "C")
915915

916-
# The notes are not show for Type[...] (because awaiting them will not work)
917-
tx.x # E: "Type[Sub[D]]" has no attribute "x"
918-
a2: C = tx # E: Incompatible types in assignment (expression has type "Type[Sub[D]]", variable has type "C")
916+
# The notes are not show for type[...] (because awaiting them will not work)
917+
tx.x # E: "type[Sub[D]]" has no attribute "x"
918+
a2: C = tx # E: Incompatible types in assignment (expression has type "type[Sub[D]]", variable has type "C")
919919

920920
class F:
921921
def __await__(self: T) -> Generator[Any, Any, T]: ...

test-data/unit/check-basic.test

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ reveal_type(b) # N: Revealed type is "Literal[False]"
378378
from typing import List
379379
x: List[int]
380380
y: List[float]
381-
y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \
381+
y = x # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[float]") \
382382
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
383383
# N: Consider using "Sequence" instead, which is covariant
384384
[builtins fixtures/list.pyi]
@@ -387,7 +387,7 @@ y = x # E: Incompatible types in assignment (expression has type "List[int]", va
387387
from typing import Dict
388388
x: Dict[str, int]
389389
y: Dict[str, float]
390-
y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]", variable has type "Dict[str, float]") \
390+
y = x # E: Incompatible types in assignment (expression has type "dict[str, int]", variable has type "dict[str, float]") \
391391
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
392392
# N: Consider using "Mapping" instead, which is covariant in the value type
393393
[builtins fixtures/dict.pyi]
@@ -420,7 +420,7 @@ def foo() -> Optional[A]:
420420

421421
def bar() -> List[A]:
422422
l = [a.A()]
423-
return l # E: Incompatible return value type (got "List[a.A]", expected "List[b.A]")
423+
return l # E: Incompatible return value type (got "list[a.A]", expected "list[b.A]")
424424

425425
def baz() -> Union[A, int]:
426426
b = True
@@ -431,37 +431,37 @@ def spam() -> Optional[A]:
431431

432432
def eggs() -> Sequence[A]:
433433
x = [a.A()]
434-
return x # E: Incompatible return value type (got "List[a.A]", expected "Sequence[b.A]")
434+
return x # E: Incompatible return value type (got "list[a.A]", expected "Sequence[b.A]")
435435

436436
def eggs2() -> Sequence[N]:
437437
x = [a.N(0)]
438-
return x # E: Incompatible return value type (got "List[a.N]", expected "Sequence[b.N]")
438+
return x # E: Incompatible return value type (got "list[a.N]", expected "Sequence[b.N]")
439439

440440
def asdf1() -> Sequence[Tuple[a.A, A]]:
441441
x = [(a.A(), a.A())]
442-
return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[a.A, b.A]]")
442+
return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[a.A, b.A]]")
443443

444444
def asdf2() -> Sequence[Tuple[A, a.A]]:
445445
x = [(a.A(), a.A())]
446-
return x # E: Incompatible return value type (got "List[Tuple[a.A, a.A]]", expected "Sequence[Tuple[b.A, a.A]]")
446+
return x # E: Incompatible return value type (got "list[tuple[a.A, a.A]]", expected "Sequence[tuple[b.A, a.A]]")
447447

448448
def arg() -> Tuple[A, A]:
449-
return A() # E: Incompatible return value type (got "A", expected "Tuple[A, A]")
449+
return A() # E: Incompatible return value type (got "A", expected "tuple[A, A]")
450450

451451
def types() -> Sequence[Type[A]]:
452452
x = [a.A]
453-
return x # E: Incompatible return value type (got "List[Type[a.A]]", expected "Sequence[Type[b.A]]")
453+
return x # E: Incompatible return value type (got "list[type[a.A]]", expected "Sequence[type[b.A]]")
454454

455455
def literal() -> Sequence[Literal[B.b]]:
456456
x = [a.B.b] # type: List[Literal[a.B.b]]
457-
return x # E: Incompatible return value type (got "List[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]")
457+
return x # E: Incompatible return value type (got "list[Literal[a.B.b]]", expected "Sequence[Literal[b.B.b]]")
458458

459459
def typeddict() -> Sequence[D]:
460460
x = [{'x': 0}] # type: List[a.D]
461-
return x # E: Incompatible return value type (got "List[a.D]", expected "Sequence[b.D]")
461+
return x # E: Incompatible return value type (got "list[a.D]", expected "Sequence[b.D]")
462462

463463
a = (a.A(), A())
464-
a.x # E: "Tuple[a.A, b.A]" has no attribute "x"
464+
a.x # E: "tuple[a.A, b.A]" has no attribute "x"
465465
[builtins fixtures/dict.pyi]
466466
[typing fixtures/typing-full.pyi]
467467

0 commit comments

Comments
 (0)