From 10f18a82b612b6127659cd64aa60c10b9cc7a904 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 18 Jun 2024 12:34:19 +0100 Subject: [PATCH] Improve fixtures for builtins.type and types.UnionType (#17400) In typeshed `builtins.type` is not generic, so it shouldn't be generic in fixtures either. Also replace `types.Union` with `types.UnionType` in test stubs, as the former doesn't exist. --- test-data/unit/check-classes.test | 2 +- test-data/unit/fixtures/isinstance.pyi | 2 +- test-data/unit/fixtures/isinstance_python3_10.pyi | 6 +++--- test-data/unit/fixtures/type.pyi | 2 +- test-data/unit/lib-stub/types.pyi | 5 +---- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index f37b0dd1dc41..427133eca10b 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -3466,7 +3466,7 @@ def foo(arg: Type[Any]): from typing import Type, Any def foo(arg: Type[Any]): reveal_type(arg.__str__) # N: Revealed type is "def () -> builtins.str" - reveal_type(arg.mro()) # N: Revealed type is "builtins.list[builtins.type[Any]]" + reveal_type(arg.mro()) # N: Revealed type is "builtins.list[builtins.type]" [builtins fixtures/type.pyi] [out] diff --git a/test-data/unit/fixtures/isinstance.pyi b/test-data/unit/fixtures/isinstance.pyi index c1446492af9b..12cef2035c2b 100644 --- a/test-data/unit/fixtures/isinstance.pyi +++ b/test-data/unit/fixtures/isinstance.pyi @@ -5,7 +5,7 @@ T = TypeVar('T') class object: def __init__(self) -> None: pass -class type(Generic[T]): +class type: def __init__(self, x) -> None: pass def __or__(self, other: type) -> type: pass diff --git a/test-data/unit/fixtures/isinstance_python3_10.pyi b/test-data/unit/fixtures/isinstance_python3_10.pyi index 7c919a216bfb..0918d10ab1ef 100644 --- a/test-data/unit/fixtures/isinstance_python3_10.pyi +++ b/test-data/unit/fixtures/isinstance_python3_10.pyi @@ -7,15 +7,15 @@ T = TypeVar('T') class object: def __init__(self) -> None: pass -class type(Generic[T]): +class type: def __init__(self, x) -> None: pass - def __or__(self, x) -> types.Union: pass + def __or__(self, x) -> types.UnionType: pass class tuple(Generic[T]): pass class function: pass -def isinstance(x: object, t: Union[Type[object], Tuple[Type[object], ...], types.Union]) -> bool: pass +def isinstance(x: object, t: Union[Type[object], Tuple[Type[object], ...], types.UnionType]) -> bool: pass def issubclass(x: object, t: Union[Type[object], Tuple[Type[object], ...]]) -> bool: pass class int: diff --git a/test-data/unit/fixtures/type.pyi b/test-data/unit/fixtures/type.pyi index 4ae8ed9ca6b1..0d93b2e1fcd6 100644 --- a/test-data/unit/fixtures/type.pyi +++ b/test-data/unit/fixtures/type.pyi @@ -13,7 +13,7 @@ class object: class list(Generic[T]): pass -class type(Generic[T]): +class type: __name__: str def __call__(self, *args: Any, **kwargs: Any) -> Any: pass def __or__(self, other: Union[type, None]) -> type: pass diff --git a/test-data/unit/lib-stub/types.pyi b/test-data/unit/lib-stub/types.pyi index dded0ba6cd9a..c3ac244c2a51 100644 --- a/test-data/unit/lib-stub/types.pyi +++ b/test-data/unit/lib-stub/types.pyi @@ -12,11 +12,8 @@ class ModuleType: class GenericAlias: ... if sys.version_info >= (3, 10): - class Union: - def __or__(self, x) -> Union: ... - class NoneType: ... class UnionType: - ... + def __or__(self, x) -> UnionType: ...