massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / coc-python-data / languageServer.0.5.59 / Typeshed / stdlib / 2 / typing.pyi
1 # Stubs for typing (Python 2.7)\r
2 \r
3 from abc import abstractmethod, ABCMeta\r
4 from types import CodeType, FrameType, TracebackType\r
5 import collections  # Needed by aliases like DefaultDict, see mypy issue 2986\r
6 \r
7 # Definitions of special type checking related constructs.  Their definitions\r
8 # are not used, so their value does not matter.\r
9 \r
10 overload = object()\r
11 Any = object()\r
12 TypeVar = object()\r
13 _promote = object()\r
14 no_type_check = object()\r
15 \r
16 class _SpecialForm(object):\r
17     def __getitem__(self, typeargs: Any) -> object: ...\r
18 \r
19 Tuple: _SpecialForm = ...\r
20 Generic: _SpecialForm = ...\r
21 Protocol: _SpecialForm = ...\r
22 Callable: _SpecialForm = ...\r
23 Type: _SpecialForm = ...\r
24 ClassVar: _SpecialForm = ...\r
25 \r
26 class GenericMeta(type): ...\r
27 \r
28 # Return type that indicates a function does not return.\r
29 # This type is equivalent to the None type, but the no-op Union is necessary to\r
30 # distinguish the None type from the None value.\r
31 NoReturn = Union[None]\r
32 \r
33 # Type aliases and type constructors\r
34 \r
35 class TypeAlias:\r
36     # Class for defining generic aliases for library types.\r
37     def __init__(self, target_type: type) -> None: ...\r
38     def __getitem__(self, typeargs: Any) -> Any: ...\r
39 \r
40 Union = TypeAlias(object)\r
41 Optional = TypeAlias(object)\r
42 List = TypeAlias(object)\r
43 Dict = TypeAlias(object)\r
44 DefaultDict = TypeAlias(object)\r
45 Set = TypeAlias(object)\r
46 FrozenSet = TypeAlias(object)\r
47 Counter = TypeAlias(object)\r
48 Deque = TypeAlias(object)\r
49 \r
50 # Predefined type variables.\r
51 AnyStr = TypeVar('AnyStr', str, unicode)\r
52 \r
53 # Abstract base classes.\r
54 \r
55 # These type variables are used by the container types.\r
56 _T = TypeVar('_T')\r
57 _S = TypeVar('_S')\r
58 _KT = TypeVar('_KT')  # Key type.\r
59 _VT = TypeVar('_VT')  # Value type.\r
60 _T_co = TypeVar('_T_co', covariant=True)  # Any type covariant containers.\r
61 _V_co = TypeVar('_V_co', covariant=True)  # Any type covariant containers.\r
62 _KT_co = TypeVar('_KT_co', covariant=True)  # Key type covariant containers.\r
63 _VT_co = TypeVar('_VT_co', covariant=True)  # Value type covariant containers.\r
64 _T_contra = TypeVar('_T_contra', contravariant=True)  # Ditto contravariant.\r
65 _TC = TypeVar('_TC', bound=Type[object])\r
66 \r
67 def runtime(cls: _TC) -> _TC: ...\r
68 \r
69 @runtime\r
70 class SupportsInt(Protocol, metaclass=ABCMeta):\r
71     @abstractmethod\r
72     def __int__(self) -> int: ...\r
73 \r
74 @runtime\r
75 class SupportsFloat(Protocol, metaclass=ABCMeta):\r
76     @abstractmethod\r
77     def __float__(self) -> float: ...\r
78 \r
79 @runtime\r
80 class SupportsComplex(Protocol, metaclass=ABCMeta):\r
81     @abstractmethod\r
82     def __complex__(self) -> complex: ...\r
83 \r
84 @runtime\r
85 class SupportsAbs(Protocol[_T_co]):\r
86     @abstractmethod\r
87     def __abs__(self) -> _T_co: ...\r
88 \r
89 @runtime\r
90 class SupportsRound(Protocol[_T_co]):\r
91     @abstractmethod\r
92     def __round__(self, ndigits: int = ...) -> _T_co: ...\r
93 \r
94 @runtime\r
95 class Reversible(Protocol[_T_co]):\r
96     @abstractmethod\r
97     def __reversed__(self) -> Iterator[_T_co]: ...\r
98 \r
99 @runtime\r
100 class Sized(Protocol, metaclass=ABCMeta):\r
101     @abstractmethod\r
102     def __len__(self) -> int: ...\r
103 \r
104 @runtime\r
105 class Hashable(Protocol, metaclass=ABCMeta):\r
106     # TODO: This is special, in that a subclass of a hashable class may not be hashable\r
107     #   (for example, list vs. object). It's not obvious how to represent this. This class\r
108     #   is currently mostly useless for static checking.\r
109     @abstractmethod\r
110     def __hash__(self) -> int: ...\r
111 \r
112 @runtime\r
113 class Iterable(Protocol[_T_co]):\r
114     @abstractmethod\r
115     def __iter__(self) -> Iterator[_T_co]: ...\r
116 \r
117 @runtime\r
118 class Iterator(Iterable[_T_co], Protocol[_T_co]):\r
119     @abstractmethod\r
120     def next(self) -> _T_co: ...\r
121     def __iter__(self) -> Iterator[_T_co]: ...\r
122 \r
123 class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):\r
124     @abstractmethod\r
125     def next(self) -> _T_co: ...\r
126 \r
127     @abstractmethod\r
128     def send(self, value: _T_contra) -> _T_co: ...\r
129 \r
130     @abstractmethod\r
131     def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ...,\r
132               tb: TracebackType = ...) -> _T_co: ...\r
133     @abstractmethod\r
134     def close(self) -> None: ...\r
135     @property\r
136     def gi_code(self) -> CodeType: ...\r
137     @property\r
138     def gi_frame(self) -> FrameType: ...\r
139     @property\r
140     def gi_running(self) -> bool: ...\r
141 \r
142 @runtime\r
143 class Container(Protocol[_T_co]):\r
144     @abstractmethod\r
145     def __contains__(self, x: object) -> bool: ...\r
146 \r
147 class Sequence(Iterable[_T_co], Container[_T_co], Sized, Reversible[_T_co], Generic[_T_co]):\r
148     @overload\r
149     @abstractmethod\r
150     def __getitem__(self, i: int) -> _T_co: ...\r
151     @overload\r
152     @abstractmethod\r
153     def __getitem__(self, s: slice) -> Sequence[_T_co]: ...\r
154     # Mixin methods\r
155     def index(self, x: Any) -> int: ...\r
156     def count(self, x: Any) -> int: ...\r
157     def __contains__(self, x: object) -> bool: ...\r
158     def __iter__(self) -> Iterator[_T_co]: ...\r
159     def __reversed__(self) -> Iterator[_T_co]: ...\r
160 \r
161 class MutableSequence(Sequence[_T], Generic[_T]):\r
162     @abstractmethod\r
163     def insert(self, index: int, object: _T) -> None: ...\r
164     @overload\r
165     @abstractmethod\r
166     def __setitem__(self, i: int, o: _T) -> None: ...\r
167     @overload\r
168     @abstractmethod\r
169     def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...\r
170     @overload\r
171     @abstractmethod\r
172     def __delitem__(self, i: int) -> None: ...\r
173     @overload\r
174     @abstractmethod\r
175     def __delitem__(self, i: slice) -> None: ...\r
176     # Mixin methods\r
177     def append(self, object: _T) -> None: ...\r
178     def extend(self, iterable: Iterable[_T]) -> None: ...\r
179     def reverse(self) -> None: ...\r
180     def pop(self, index: int = ...) -> _T: ...\r
181     def remove(self, object: _T) -> None: ...\r
182     def __iadd__(self, x: Iterable[_T]) -> MutableSequence[_T]: ...\r
183 \r
184 class AbstractSet(Sized, Iterable[_T_co], Container[_T_co], Generic[_T_co]):\r
185     @abstractmethod\r
186     def __contains__(self, x: object) -> bool: ...\r
187     # Mixin methods\r
188     def __le__(self, s: AbstractSet[Any]) -> bool: ...\r
189     def __lt__(self, s: AbstractSet[Any]) -> bool: ...\r
190     def __gt__(self, s: AbstractSet[Any]) -> bool: ...\r
191     def __ge__(self, s: AbstractSet[Any]) -> bool: ...\r
192     def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...\r
193     def __or__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ...\r
194     def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ...\r
195     def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ...\r
196     # TODO: argument can be any container?\r
197     def isdisjoint(self, s: AbstractSet[Any]) -> bool: ...\r
198 \r
199 class MutableSet(AbstractSet[_T], Generic[_T]):\r
200     @abstractmethod\r
201     def add(self, x: _T) -> None: ...\r
202     @abstractmethod\r
203     def discard(self, x: _T) -> None: ...\r
204     # Mixin methods\r
205     def clear(self) -> None: ...\r
206     def pop(self) -> _T: ...\r
207     def remove(self, element: _T) -> None: ...\r
208     def __ior__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ...\r
209     def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...\r
210     def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ...\r
211     def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...\r
212 \r
213 class MappingView(Sized):\r
214     def __len__(self) -> int: ...\r
215 \r
216 class ItemsView(AbstractSet[Tuple[_KT_co, _VT_co]], MappingView, Generic[_KT_co, _VT_co]):\r
217     def __contains__(self, o: object) -> bool: ...\r
218     def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...\r
219 \r
220 class KeysView(AbstractSet[_KT_co], MappingView, Generic[_KT_co]):\r
221     def __contains__(self, o: object) -> bool: ...\r
222     def __iter__(self) -> Iterator[_KT_co]: ...\r
223 \r
224 class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]):\r
225     def __contains__(self, o: object) -> bool: ...\r
226     def __iter__(self) -> Iterator[_VT_co]: ...\r
227 \r
228 @runtime\r
229 class ContextManager(Protocol[_T_co]):\r
230     def __enter__(self) -> _T_co: ...\r
231     def __exit__(self, exc_type: Optional[Type[BaseException]],\r
232                  exc_value: Optional[BaseException],\r
233                  traceback: Optional[TracebackType]) -> Optional[bool]: ...\r
234 \r
235 class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]):\r
236     # TODO: We wish the key type could also be covariant, but that doesn't work,\r
237     # see discussion in https: //github.com/python/typing/pull/273.\r
238     @abstractmethod\r
239     def __getitem__(self, k: _KT) -> _VT_co:\r
240         ...\r
241     # Mixin methods\r
242     @overload\r
243     def get(self, k: _KT) -> Optional[_VT_co]: ...\r
244     @overload\r
245     def get(self, k: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]: ...\r
246     def keys(self) -> list[_KT]: ...\r
247     def values(self) -> list[_VT_co]: ...\r
248     def items(self) -> list[Tuple[_KT, _VT_co]]: ...\r
249     def iterkeys(self) -> Iterator[_KT]: ...\r
250     def itervalues(self) -> Iterator[_VT_co]: ...\r
251     def iteritems(self) -> Iterator[Tuple[_KT, _VT_co]]: ...\r
252     def __contains__(self, o: object) -> bool: ...\r
253 \r
254 class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):\r
255     @abstractmethod\r
256     def __setitem__(self, k: _KT, v: _VT) -> None: ...\r
257     @abstractmethod\r
258     def __delitem__(self, v: _KT) -> None: ...\r
259 \r
260     def clear(self) -> None: ...\r
261     @overload\r
262     def pop(self, k: _KT) -> _VT: ...\r
263     @overload\r
264     def pop(self, k: _KT, default: Union[_VT, _T] = ...) -> Union[_VT, _T]: ...\r
265     def popitem(self) -> Tuple[_KT, _VT]: ...\r
266     def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ...\r
267     @overload\r
268     def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...\r
269     @overload\r
270     def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...\r
271     @overload\r
272     def update(self, **kwargs: _VT) -> None: ...\r
273 \r
274 Text = unicode\r
275 \r
276 TYPE_CHECKING = True\r
277 \r
278 class IO(Iterator[AnyStr], Generic[AnyStr]):\r
279     # TODO detach\r
280     # TODO use abstract properties\r
281     @property\r
282     def mode(self) -> str: ...\r
283     @property\r
284     def name(self) -> str: ...\r
285     @abstractmethod\r
286     def close(self) -> None: ...\r
287     @property\r
288     def closed(self) -> bool: ...\r
289     @abstractmethod\r
290     def fileno(self) -> int: ...\r
291     @abstractmethod\r
292     def flush(self) -> None: ...\r
293     @abstractmethod\r
294     def isatty(self) -> bool: ...\r
295     # TODO what if n is None?\r
296     @abstractmethod\r
297     def read(self, n: int = ...) -> AnyStr: ...\r
298     @abstractmethod\r
299     def readable(self) -> bool: ...\r
300     @abstractmethod\r
301     def readline(self, limit: int = ...) -> AnyStr: ...\r
302     @abstractmethod\r
303     def readlines(self, hint: int = ...) -> list[AnyStr]: ...\r
304     @abstractmethod\r
305     def seek(self, offset: int, whence: int = ...) -> int: ...\r
306     @abstractmethod\r
307     def seekable(self) -> bool: ...\r
308     @abstractmethod\r
309     def tell(self) -> int: ...\r
310     @abstractmethod\r
311     def truncate(self, size: Optional[int] = ...) -> int: ...\r
312     @abstractmethod\r
313     def writable(self) -> bool: ...\r
314     # TODO buffer objects\r
315     @abstractmethod\r
316     def write(self, s: AnyStr) -> int: ...\r
317     @abstractmethod\r
318     def writelines(self, lines: Iterable[AnyStr]) -> None: ...\r
319 \r
320     @abstractmethod\r
321     def next(self) -> AnyStr: ...\r
322     @abstractmethod\r
323     def __iter__(self) -> Iterator[AnyStr]: ...\r
324     @abstractmethod\r
325     def __enter__(self) -> IO[AnyStr]: ...\r
326     @abstractmethod\r
327     def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException],\r
328                  traceback: Optional[TracebackType]) -> bool: ...\r
329 \r
330 class BinaryIO(IO[str]):\r
331     # TODO readinto\r
332     # TODO read1?\r
333     # TODO peek?\r
334     @abstractmethod\r
335     def __enter__(self) -> BinaryIO: ...\r
336 \r
337 class TextIO(IO[unicode]):\r
338     # TODO use abstractproperty\r
339     @property\r
340     def buffer(self) -> BinaryIO: ...\r
341     @property\r
342     def encoding(self) -> str: ...\r
343     @property\r
344     def errors(self) -> Optional[str]: ...\r
345     @property\r
346     def line_buffering(self) -> bool: ...\r
347     @property\r
348     def newlines(self) -> Any: ...  # None, str or tuple\r
349     @abstractmethod\r
350     def __enter__(self) -> TextIO: ...\r
351 \r
352 class ByteString(Sequence[int], metaclass=ABCMeta): ...\r
353 \r
354 class Match(Generic[AnyStr]):\r
355     pos = 0\r
356     endpos = 0\r
357     lastindex = 0\r
358     lastgroup = ...  # type: AnyStr\r
359     string = ...  # type: AnyStr\r
360 \r
361     # The regular expression object whose match() or search() method produced\r
362     # this match instance.\r
363     re = ...  # type: 'Pattern[AnyStr]'\r
364 \r
365     def expand(self, template: AnyStr) -> AnyStr: ...\r
366 \r
367     @overload\r
368     def group(self, group1: int = ...) -> AnyStr: ...\r
369     @overload\r
370     def group(self, group1: str) -> AnyStr: ...\r
371     @overload\r
372     def group(self, group1: int, group2: int,\r
373               *groups: int) -> Sequence[AnyStr]: ...\r
374     @overload\r
375     def group(self, group1: str, group2: str,\r
376               *groups: str) -> Sequence[AnyStr]: ...\r
377 \r
378     def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ...\r
379     def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ...\r
380     def start(self, group: Union[int, str] = ...) -> int: ...\r
381     def end(self, group: Union[int, str] = ...) -> int: ...\r
382     def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ...\r
383 \r
384 class Pattern(Generic[AnyStr]):\r
385     flags = 0\r
386     groupindex = 0\r
387     groups = 0\r
388     pattern = ...  # type: AnyStr\r
389 \r
390     def search(self, string: AnyStr, pos: int = ...,\r
391                endpos: int = ...) -> Optional[Match[AnyStr]]: ...\r
392     def match(self, string: AnyStr, pos: int = ...,\r
393               endpos: int = ...) -> Optional[Match[AnyStr]]: ...\r
394     def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ...\r
395     def findall(self, string: AnyStr, pos: int = ...,\r
396                 endpos: int = ...) -> list[Any]: ...\r
397     def finditer(self, string: AnyStr, pos: int = ...,\r
398                  endpos: int = ...) -> Iterator[Match[AnyStr]]: ...\r
399 \r
400     @overload\r
401     def sub(self, repl: AnyStr, string: AnyStr,\r
402             count: int = ...) -> AnyStr: ...\r
403     @overload\r
404     def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,\r
405             count: int = ...) -> AnyStr: ...\r
406 \r
407     @overload\r
408     def subn(self, repl: AnyStr, string: AnyStr,\r
409              count: int = ...) -> Tuple[AnyStr, int]: ...\r
410     @overload\r
411     def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,\r
412              count: int = ...) -> Tuple[AnyStr, int]: ...\r
413 \r
414 # Functions\r
415 \r
416 def get_type_hints(obj: Callable, globalns: Optional[dict[Text, Any]] = ...,\r
417                    localns: Optional[dict[Text, Any]] = ...) -> None: ...\r
418 \r
419 def cast(tp: Type[_T], obj: Any) -> _T: ...\r
420 \r
421 # Type constructors\r
422 \r
423 # NamedTuple is special-cased in the type checker\r
424 class NamedTuple(tuple):\r
425     _fields = ...  # type: Tuple[str, ...]\r
426 \r
427     def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., *,\r
428                  verbose: bool = ..., rename: bool = ..., **kwargs: Any) -> None: ...\r
429 \r
430     @classmethod\r
431     def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ...\r
432 \r
433     def _asdict(self) -> dict: ...\r
434     def _replace(self: _T, **kwargs: Any) -> _T: ...\r
435 \r
436 def NewType(name: str, tp: Type[_T]) -> Type[_T]: ...\r