Skip to content

Commit 82cb8c2

Browse files
Fix conditional imports within collections (#5040)
Co-authored-by: Eric Traut <[email protected]>
1 parent 0fa7e73 commit 82cb8c2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

stdlib/collections/__init__.pyi

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import sys
2-
import typing
32
from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload
43

54
if sys.version_info < (3, 10):
65
from _collections_abc import *
6+
else:
7+
from typing import (
8+
Callable,
9+
ItemsView,
10+
Iterable,
11+
Iterator,
12+
KeysView,
13+
Mapping,
14+
MutableMapping,
15+
MutableSequence,
16+
Reversible,
17+
Sequence,
18+
ValuesView,
19+
)
720

821
_S = TypeVar("_S")
922
_T = TypeVar("_T")
@@ -103,7 +116,7 @@ class UserString(Sequence[str]):
103116
def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ...
104117
def count(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ...
105118
if sys.version_info >= (3, 8):
106-
def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> bytes: ...
119+
def encode(self: UserString, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> bytes: ...
107120
else:
108121
def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UserStringT: ...
109122
def endswith(self, suffix: Union[str, Tuple[str, ...]], start: Optional[int] = ..., end: Optional[int] = ...) -> bool: ...
@@ -281,9 +294,9 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
281294
def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ...
282295
@property
283296
def maps(self) -> List[Mapping[_KT, _VT]]: ...
284-
def new_child(self, m: Mapping[_KT, _VT] = ...) -> typing.ChainMap[_KT, _VT]: ...
297+
def new_child(self, m: Mapping[_KT, _VT] = ...) -> ChainMap[_KT, _VT]: ...
285298
@property
286-
def parents(self) -> typing.ChainMap[_KT, _VT]: ...
299+
def parents(self) -> ChainMap[_KT, _VT]: ...
287300
def __setitem__(self, k: _KT, v: _VT) -> None: ...
288301
def __delitem__(self, v: _KT) -> None: ...
289302
def __getitem__(self, k: _KT) -> _VT: ...

0 commit comments

Comments
 (0)