Skip to content

Commit

Permalink
Improve fixtures for builtins.type and types.UnionType (python#17400)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JukkaL authored Jun 18, 2024
1 parent 59b2df4 commit 10f18a8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fixtures/isinstance.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/fixtures/isinstance_python3_10.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fixtures/type.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions test-data/unit/lib-stub/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

0 comments on commit 10f18a8

Please sign in to comment.