Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd86abd

Browse files
authored
Use PEP 604 union syntax in test output (#20402)
Followup to #20332 Change the test output from `Union` and `Optional` to the PEP 604 union syntax. This is already the default for `--python-version 3.10` and later if `--force-union-syntax` isn't used.
1 parent 12d53f6 commit fd86abd

File tree

79 files changed

+1574
-1569
lines changed

Some content is hidden

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

79 files changed

+1574
-1569
lines changed

mypy/test/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def parse_options(
357357
options = Options()
358358
options.error_summary = False
359359
options.hide_error_codes = True
360-
options.force_union_syntax = True
360+
options.overwrite_union_syntax = True
361361

362362
# Allow custom python version to override testfile_pyversion.
363363
if all(flag.split("=")[0] != "--python-version" for flag in flag_list):

mypy/test/testcheck.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def run_case_once(
136136
options = parse_options(original_program_text, testcase, incremental_step)
137137
options.use_builtins_fixtures = True
138138
options.show_traceback = True
139+
options.overwrite_union_syntax = True
139140

140141
if options.num_workers:
141142
options.fixed_format_cache = True
@@ -151,8 +152,6 @@ def run_case_once(
151152
options.hide_error_codes = False
152153
if "abstract" not in testcase.file:
153154
options.allow_empty_bodies = not testcase.name.endswith("_no_empty")
154-
if "union-error" not in testcase.file and "Pep604" not in testcase.name:
155-
options.force_union_syntax = True
156155

157156
if incremental_step and options.incremental or options.num_workers > 0:
158157
# Don't overwrite # flags: --no-incremental in incremental test cases

mypy/test/testfinegrained.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def get_options(self, source: str, testcase: DataDrivenTestCase, build_cache: bo
152152
options.use_fine_grained_cache = self.use_cache and not build_cache
153153
options.cache_fine_grained = self.use_cache
154154
options.local_partial_types = True
155+
options.overwrite_union_syntax = True
155156
options.export_types = "inspect" in testcase.file
156157
# Treat empty bodies safely for these test cases.
157158
options.allow_empty_bodies = not testcase.name.endswith("_no_empty")

mypy/test/testmerge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ 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.overwrite_union_syntax = True
105106
main_path = os.path.join(test_temp_dir, "main")
106107

107108
self.str_conv.options = options

mypy/test/testparse.py

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

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

mypy/test/testsemanal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Opti
3838
options.semantic_analysis_only = True
3939
options.show_traceback = True
4040
options.python_version = PYTHON3_VERSION
41+
options.overwrite_union_syntax = True
4142
return options
4243

4344

mypy/test/testtransform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ 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.overwrite_union_syntax = True
4142
result = build.build(
4243
sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir
4344
)

mypy/test/testtypegen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ 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.overwrite_union_syntax = True
3839
result = build.build(
3940
sources=[BuildSource("main", None, src)],
4041
options=options,

test-data/unit/check-annotated.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
88
from typing import Union
99
from typing_extensions import Annotated
1010
x: Annotated[Union[int, str], ...]
11-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
11+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
1212
[builtins fixtures/tuple.pyi]
1313

1414
[case testAnnotated2]
@@ -51,7 +51,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
5151
from typing import Union
5252
from typing_extensions import Annotated
5353
x: Annotated[Annotated[Union[int, str], ...], ...]
54-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
54+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
5555
[builtins fixtures/tuple.pyi]
5656

5757
[case testAnnotatedNestedBadType]
@@ -114,7 +114,7 @@ from typing_extensions import Annotated
114114
T = TypeVar('T')
115115
Alias = Annotated[Union[T, str], ...]
116116
x: Alias[int]
117-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
117+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
118118
[builtins fixtures/tuple.pyi]
119119

120120
[case testAnnotatedSecondParamNonType]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def f() -> None:
205205
pass
206206

207207
async for z in C(): # type: Union[int, str]
208-
reveal_type(z) # N: Revealed type is "Union[builtins.int, builtins.str]"
208+
reveal_type(z) # N: Revealed type is "builtins.int | builtins.str"
209209
[builtins fixtures/async_await.pyi]
210210
[typing fixtures/typing-async.pyi]
211211

@@ -952,7 +952,7 @@ async def foo(x: B) -> A: ...
952952
async def foo(x): ...
953953

954954
async def bar(x: Union[A, B]) -> None:
955-
reveal_type(await foo(x)) # N: Revealed type is "Union[__main__.B, __main__.A]"
955+
reveal_type(await foo(x)) # N: Revealed type is "__main__.B | __main__.A"
956956

957957
[builtins fixtures/async_await.pyi]
958958
[typing fixtures/typing-async.pyi]

0 commit comments

Comments
 (0)