Skip to content
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
2 changes: 1 addition & 1 deletion mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def parse_options(
options = Options()
options.error_summary = False
options.hide_error_codes = True
options.force_union_syntax = True
options.overwrite_union_syntax = True

# Allow custom python version to override testfile_pyversion.
if all(flag.split("=")[0] != "--python-version" for flag in flag_list):
Expand Down
3 changes: 1 addition & 2 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def run_case_once(
options = parse_options(original_program_text, testcase, incremental_step)
options.use_builtins_fixtures = True
options.show_traceback = True
options.overwrite_union_syntax = True

if options.num_workers:
options.fixed_format_cache = True
Expand All @@ -151,8 +152,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 "union-error" not in testcase.file and "Pep604" not in testcase.name:
options.force_union_syntax = True

if incremental_step and options.incremental or options.num_workers > 0:
# Don't overwrite # flags: --no-incremental in incremental test cases
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testfinegrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def get_options(self, source: str, testcase: DataDrivenTestCase, build_cache: bo
options.use_fine_grained_cache = self.use_cache and not build_cache
options.cache_fine_grained = self.use_cache
options.local_partial_types = True
options.overwrite_union_syntax = True
options.export_types = "inspect" in testcase.file
# Treat empty bodies safely for these test cases.
options.allow_empty_bodies = not testcase.name.endswith("_no_empty")
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def build(self, source: str, testcase: DataDrivenTestCase) -> BuildResult | None
options.export_types = True
options.show_traceback = True
options.allow_empty_bodies = True
options.overwrite_union_syntax = True
main_path = os.path.join(test_temp_dir, "main")

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

if testcase.file.endswith("python310.test"):
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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.overwrite_union_syntax = True
return options


Expand Down
1 change: 1 addition & 0 deletions mypy/test/testtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_transform(testcase: DataDrivenTestCase) -> None:
options.use_builtins_fixtures = True
options.semantic_analysis_only = True
options.show_traceback = True
options.overwrite_union_syntax = True
result = build.build(
sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir
)
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testtypegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
options.export_types = True
options.preserve_asts = True
options.allow_empty_bodies = True
options.overwrite_union_syntax = True
result = build.build(
sources=[BuildSource("main", None, src)],
options=options,
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-annotated.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
from typing import Union
from typing_extensions import Annotated
x: Annotated[Union[int, str], ...]
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
[builtins fixtures/tuple.pyi]

[case testAnnotated2]
Expand Down Expand Up @@ -51,7 +51,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
from typing import Union
from typing_extensions import Annotated
x: Annotated[Annotated[Union[int, str], ...], ...]
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
[builtins fixtures/tuple.pyi]

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

[case testAnnotatedSecondParamNonType]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async def f() -> None:
pass

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

Expand Down Expand Up @@ -952,7 +952,7 @@ async def foo(x: B) -> A: ...
async def foo(x): ...

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

[builtins fixtures/async_await.pyi]
[typing fixtures/typing-async.pyi]
Expand Down
12 changes: 6 additions & 6 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ reveal_type(__file__) # N: Revealed type is "builtins.str"
reveal_type(__package__) # N: Revealed type is "builtins.str"
reveal_type(__annotations__) # N: Revealed type is "builtins.dict[builtins.str, Any]"
# This will actually reveal Union[importlib.machinery.ModuleSpec, None]
reveal_type(__spec__) # N: Revealed type is "Union[builtins.object, None]"
reveal_type(__spec__) # N: Revealed type is "builtins.object | None"

import module
reveal_type(module.__name__) # N: Revealed type is "builtins.str"
Expand Down Expand Up @@ -416,18 +416,18 @@ D = TypedDict('D', {'y': int})

def foo() -> Optional[A]:
b = True
return a.A() if b else None # E: Incompatible return value type (got "Optional[a.A]", expected "Optional[b.A]")
return a.A() if b else None # E: Incompatible return value type (got "a.A | None", expected "b.A | None")

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

def baz() -> Union[A, int]:
b = True
return a.A() if b else 10 # E: Incompatible return value type (got "Union[a.A, int]", expected "Union[b.A, int]")
return a.A() if b else 10 # E: Incompatible return value type (got "a.A | int", expected "b.A | int")

def spam() -> Optional[A]:
return a.A() # E: Incompatible return value type (got "a.A", expected "Optional[b.A]")
return a.A() # E: Incompatible return value type (got "a.A", expected "b.A | None")

def eggs() -> Sequence[A]:
x = [a.A()]
Expand Down Expand Up @@ -516,11 +516,11 @@ x: """
str

"""
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"

y: """(
int |
str
)
"""
reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(y) # N: Revealed type is "builtins.int | builtins.str"
10 changes: 5 additions & 5 deletions test-data/unit/check-callable.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ x = 5 # type: Union[int, Callable[[], str], Callable[[], int]]

if callable(x):
y = x() + 2 # E: Unsupported operand types for + ("str" and "int") \
# N: Left operand is of type "Union[str, int]"
# N: Left operand is of type "str | int"
else:
z = x + 6

Expand All @@ -62,7 +62,7 @@ if callable(x):
y = x() + 'test'
else:
z = x + 6 # E: Unsupported operand types for + ("str" and "int") \
# N: Left operand is of type "Union[int, str]"
# N: Left operand is of type "int | str"

[builtins fixtures/callable.pyi]

Expand Down Expand Up @@ -156,7 +156,7 @@ if callable(x) and x() == 'test':
x()
else:
x + 5 # E: Unsupported left operand type for + ("Callable[[], str]") \
# N: Left operand is of type "Union[int, Callable[[], str]]"
# N: Left operand is of type "int | Callable[[], str]"

[builtins fixtures/callable.pyi]

Expand Down Expand Up @@ -280,9 +280,9 @@ T = Union[Union[int, Callable[[], int]], Union[str, Callable[[], str]]]

def f(t: T) -> None:
if callable(t):
reveal_type(t()) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(t()) # N: Revealed type is "builtins.int | builtins.str"
else:
reveal_type(t) # N: Revealed type is "Union[builtins.int, builtins.str]"
reveal_type(t) # N: Revealed type is "builtins.int | builtins.str"

[builtins fixtures/callable.pyi]

Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-class-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class HasNone(NamedTuple):
x: int
y: Optional[int] = None

reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, builtins.int | None, fallback=__main__.HasNone]"

class Parameterized(NamedTuple):
x: int
Expand Down Expand Up @@ -425,7 +425,7 @@ class HasNone(NamedTuple):
x: int
y: Optional[int] = None

reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, builtins.int | None, fallback=__main__.HasNone]"
HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int"
HasNone(1, y=None)
HasNone(1, y=2)
Expand Down
Loading