Skip to content

Remove force_uppercase_builtins default from test helpers #19173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,12 @@ def local_sys_path_set() -> Iterator[None]:


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


def normalize_error_messages(messages: list[str]) -> list[str]:
Expand Down Expand Up @@ -353,7 +354,6 @@ def parse_options(
options = Options()
options.error_summary = False
options.hide_error_codes = True
options.force_uppercase_builtins = True
options.force_union_syntax = True

# Allow custom python version to override testfile_pyversion.
Expand Down
2 changes: 0 additions & 2 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ def run_case_once(
options.hide_error_codes = False
if "abstract" not in testcase.file:
options.allow_empty_bodies = not testcase.name.endswith("_no_empty")
if "lowercase" not in testcase.file:
options.force_uppercase_builtins = True
if "union-error" not in testcase.file:
options.force_union_syntax = True

Expand Down
2 changes: 0 additions & 2 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
args.append("--hide-error-codes")
if "--disallow-empty-bodies" not in args:
args.append("--allow-empty-bodies")
if "--no-force-uppercase-builtins" not in args:
args.append("--force-uppercase-builtins")
if "--no-force-union-syntax" not in args:
args.append("--force-union-syntax")
# Type check the program.
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def build(self, source: str, testcase: DataDrivenTestCase) -> BuildResult | None
options.export_types = True
options.show_traceback = True
options.allow_empty_bodies = True
options.force_uppercase_builtins = True
main_path = os.path.join(test_temp_dir, "main")

self.str_conv.options = options
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_parser(testcase: DataDrivenTestCase) -> None:
The argument contains the description of the test case.
"""
options = Options()
options.force_uppercase_builtins = True
options.hide_error_codes = True

if testcase.file.endswith("python310.test"):
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
"--no-error-summary",
"--hide-error-codes",
"--allow-empty-bodies",
"--force-uppercase-builtins",
"--test-env", # Speeds up some checks
]
interpreter = python3_path
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Opti
options.semantic_analysis_only = True
options.show_traceback = True
options.python_version = PYTHON3_VERSION
options.force_uppercase_builtins = True
return options


Expand Down
1 change: 0 additions & 1 deletion mypy/test/testtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_transform(testcase: DataDrivenTestCase) -> None:
options.use_builtins_fixtures = True
options.semantic_analysis_only = True
options.show_traceback = True
options.force_uppercase_builtins = True
result = build.build(
sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir
)
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testtypegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
options.export_types = True
options.preserve_asts = True
options.allow_empty_bodies = True
options.force_uppercase_builtins = True
result = build.build(
sources=[BuildSource("main", None, src)],
options=options,
Expand Down
19 changes: 7 additions & 12 deletions mypy/test/testtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Expression,
NameExpr,
)
from mypy.options import Options
from mypy.plugins.common import find_shallow_matching_overload_item
from mypy.state import state
from mypy.subtypes import is_more_precise, is_proper_subtype, is_same_type, is_subtype
Expand Down Expand Up @@ -130,17 +129,13 @@ def test_callable_type_with_var_args(self) -> None:
)
assert_equal(str(c3), "def (X? =, *Y?) -> Any")

def test_tuple_type_upper(self) -> None:
options = Options()
options.force_uppercase_builtins = True
assert_equal(TupleType([], self.fx.std_tuple).str_with_options(options), "Tuple[()]")
assert_equal(TupleType([self.x], self.fx.std_tuple).str_with_options(options), "Tuple[X?]")
assert_equal(
TupleType(
[self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple
).str_with_options(options),
"Tuple[X?, Any]",
)
def test_tuple_type_str(self) -> None:
t1 = TupleType([], self.fx.std_tuple)
assert_equal(str(t1), "tuple[()]")
t2 = TupleType([self.x], self.fx.std_tuple)
assert_equal(str(t2), "tuple[X?]")
t3 = TupleType([self.x, AnyType(TypeOfAny.special_form)], self.fx.std_tuple)
assert_equal(str(t3), "tuple[X?, Any]")

def test_type_variable_binding(self) -> None:
assert_equal(
Expand Down
18 changes: 9 additions & 9 deletions test-data/unit/check-abstract.test
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def f(cls: Type[A]) -> A:
def g() -> A:
return A() # E: Cannot instantiate abstract class "A" with abstract attribute "m"

f(A) # E: Only concrete class can be given where "Type[A]" is expected
f(B) # E: Only concrete class can be given where "Type[A]" is expected
f(A) # E: Only concrete class can be given where "type[A]" is expected
f(B) # E: Only concrete class can be given where "type[A]" is expected
f(C) # OK
x: Type[B]
f(x) # OK
Expand All @@ -207,7 +207,7 @@ class Class:
def method(self) -> None:
pass

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

class Child(Class):
def method(self) -> None: ...
Expand Down Expand Up @@ -235,7 +235,7 @@ Alias = A
GoodAlias = C
Alias() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
GoodAlias()
f(Alias) # E: Only concrete class can be given where "Type[A]" is expected
f(Alias) # E: Only concrete class can be given where "type[A]" is expected
f(GoodAlias)
[out]

Expand All @@ -255,18 +255,18 @@ class C(B):
var: Type[A]
var()
if int():
var = A # E: Can only assign concrete classes to a variable of type "Type[A]"
var = A # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var = B # E: Can only assign concrete classes to a variable of type "Type[A]"
var = B # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var = C # OK

var_old = None # type: Type[A] # Old syntax for variable annotations
var_old()
if int():
var_old = A # E: Can only assign concrete classes to a variable of type "Type[A]"
var_old = A # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var_old = B # E: Can only assign concrete classes to a variable of type "Type[A]"
var_old = B # E: Can only assign concrete classes to a variable of type "type[A]"
if int():
var_old = C # OK

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

[case testInstantiationAbstractsInTypeForClassMethods]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-annotated.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ from typing_extensions import Annotated
T = TypeVar('T')
Alias = Annotated[Tuple[T, T], ...]
x: Alias[int]
reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]"
reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]"
[builtins fixtures/tuple.pyi]

[case testAnnotatedAliasGenericUnion]
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def f() -> None:
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]
[out]
main:4: error: "List[int]" has no attribute "__aiter__" (not async iterable)
main:4: error: "list[int]" has no attribute "__aiter__" (not async iterable)

[case testAsyncForErrorNote]

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

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

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

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

class F:
def __await__(self: T) -> Generator[Any, Any, T]: ...
Expand Down
24 changes: 12 additions & 12 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ reveal_type(b) # N: Revealed type is "Literal[False]"
from typing import List
x: List[int]
y: List[float]
y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \
y = x # E: Incompatible types in assignment (expression has type "list[int]", variable has type "list[float]") \
# N: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
# N: Consider using "Sequence" instead, which is covariant
[builtins fixtures/list.pyi]
Expand All @@ -387,7 +387,7 @@ y = x # E: Incompatible types in assignment (expression has type "List[int]", va
from typing import Dict
x: Dict[str, int]
y: Dict[str, float]
y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]", variable has type "Dict[str, float]") \
y = x # E: Incompatible types in assignment (expression has type "dict[str, int]", variable has type "dict[str, float]") \
# N: "dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance \
# N: Consider using "Mapping" instead, which is covariant in the value type
[builtins fixtures/dict.pyi]
Expand Down Expand Up @@ -420,7 +420,7 @@ def foo() -> Optional[A]:

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

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

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

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

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

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

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

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

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

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

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

Expand Down
Loading