Skip to content

Commit 7a623f2

Browse files
elazarggvanrossum
authored andcommitted
Dedicated TypeVar for type.__subclasses__ (#639)
1 parent 58d864d commit 7a623f2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Python 3, and stub files conform to Python 3 syntax.
55

66
from typing import (
7-
TypeVar, Iterator, Iterable, overload, Type,
7+
TypeVar, Iterator, Iterable, overload,
88
Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set,
99
AbstractSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs,
1010
SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping,
@@ -21,6 +21,7 @@ _T1 = TypeVar('_T1')
2121
_T2 = TypeVar('_T2')
2222
_T3 = TypeVar('_T3')
2323
_T4 = TypeVar('_T4')
24+
_TT = TypeVar('_TT', bound='type')
2425

2526
class staticmethod: pass # Special, only valid as a decorator.
2627
class classmethod: pass # Special, only valid as a decorator.
@@ -60,7 +61,7 @@ class type:
6061
# Note: the documentation doesnt specify what the return type is, the standard
6162
# implementation seems to be returning a list.
6263
def mro(self) -> List[type]: ...
63-
def __subclasses__(self: Type[_T]) -> List[Type[_T]]: ...
64+
def __subclasses__(self: _TT) -> List[_TT]: ...
6465

6566
class int(SupportsInt, SupportsFloat, SupportsAbs[int]):
6667
@overload

stdlib/3/builtins.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stubs for builtins (Python 3)
22

33
from typing import (
4-
TypeVar, Iterator, Iterable, overload, Type,
4+
TypeVar, Iterator, Iterable, overload,
55
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
66
Set, AbstractSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsBytes,
77
SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView, ByteString, Optional
@@ -22,6 +22,7 @@ _T1 = TypeVar('_T1')
2222
_T2 = TypeVar('_T2')
2323
_T3 = TypeVar('_T3')
2424
_T4 = TypeVar('_T4')
25+
_TT = TypeVar('_TT', bound='type')
2526

2627
class staticmethod: pass # Special, only valid as a decorator.
2728
class classmethod: pass # Special, only valid as a decorator.
@@ -57,7 +58,7 @@ class type:
5758
@overload
5859
def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ...
5960
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
60-
def __subclasses__(self: Type[_T]) -> List[Type[_T]]: ...
61+
def __subclasses__(self: _TT) -> List[_TT]: ...
6162
# Note: the documentation doesnt specify what the return type is, the standard
6263
# implementation seems to be returning a list.
6364
def mro(self) -> List[type]: ...

0 commit comments

Comments
 (0)