Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b739e0

Browse files
authored
Split stdlib into Python 2 and 3 versions (#5442)
All new files in stdlib/@python2 are straight copies of the corresponding files in stdlib.
1 parent 8971c24 commit 5b739e0

218 files changed

Lines changed: 18067 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,13 @@ To automatically check your code before committing, copy the file
4444
### Standard library stubs
4545

4646
The `stdlib` directory contains stubs for modules in the
47-
Python standard library — which
47+
Python 3 standard library — which
4848
includes pure Python modules, dynamically loaded extension modules,
4949
hard-linked extension modules, and the builtins. The `VERSIONS` file lists
5050
the versions of Python where the module is available.
5151

52-
The `stdlib/@python2` subdirectory contains Python 2-only stubs,
53-
both for modules that must be kept different for Python 2 and 3, like
54-
`builtins.pyi`, and for modules that only existed in Python 2, like
55-
`ConfigParser.pyi`. The latter group of modules are not listed in
56-
`VERSIONS`.
57-
58-
Note that if a package is present in `@python2`, any stub in the main
59-
`stdlib` directory should be ignored when looking for Python 2 stubs. For
60-
example, typeshed contains files `stdlib/@python2/collections.pyi` and
61-
`stdlib/collections/abc.pyi`. A client looking for stubs for
62-
`collections.abc` in Python 2 should not pick up the latter file, but
63-
instead report that the module does not exist.
52+
Stubs for Python 2 are available in the `stdlib/@python2` subdirectory.
53+
Modules that are only available for Python 2 are not listed in `VERSIONS`.
6454

6555
### Third-party library stubs
6656

@@ -72,8 +62,8 @@ contains the following:
7262
to `True`, Python 2 defaults to `False`), and dependency on other type stub
7363
packages.
7464
* Stubs (i.e. `*.pyi` files) for packages and modules that are shipped in the
75-
source distribution. Similar to standard library, if the Python 2 version of
76-
the stubs must be kept *separate*, it can be put in a `@python` subdirectory.
65+
source distribution. If the Python 2 version of the stubs must be kept
66+
*separate*, they can be put in a `@python2` subdirectory.
7767
* (Rarely) some docs specific to a given type stub package in `README` file.
7868

7969
When a third party stub is

stdlib/@python2/__future__.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
from typing import List
3+
4+
class _Feature:
5+
def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ...
6+
def getOptionalRelease(self) -> sys._version_info: ...
7+
def getMandatoryRelease(self) -> sys._version_info: ...
8+
compiler_flag: int
9+
10+
absolute_import: _Feature
11+
division: _Feature
12+
generators: _Feature
13+
nested_scopes: _Feature
14+
print_function: _Feature
15+
unicode_literals: _Feature
16+
with_statement: _Feature
17+
if sys.version_info >= (3, 0):
18+
barry_as_FLUFL: _Feature
19+
20+
if sys.version_info >= (3, 5):
21+
generator_stop: _Feature
22+
23+
if sys.version_info >= (3, 7):
24+
annotations: _Feature
25+
26+
all_feature_names: List[str] # undocumented

stdlib/@python2/__main__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from typing import Any
2+
3+
def __getattr__(name: str) -> Any: ...

stdlib/@python2/_bisect.pyi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
from _typeshed import SupportsLessThan
3+
from typing import Callable, MutableSequence, Optional, Sequence, TypeVar
4+
5+
_T = TypeVar("_T")
6+
7+
if sys.version_info >= (3, 10):
8+
def bisect_left(
9+
a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ..., *, key: Optional[Callable[[_T], SupportsLessThan]] = ...
10+
) -> int: ...
11+
def bisect_right(
12+
a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ..., *, key: Optional[Callable[[_T], SupportsLessThan]] = ...
13+
) -> int: ...
14+
def insort_left(
15+
a: MutableSequence[_T],
16+
x: _T,
17+
lo: int = ...,
18+
hi: Optional[int] = ...,
19+
*,
20+
key: Optional[Callable[[_T], SupportsLessThan]] = ...,
21+
) -> None: ...
22+
def insort_right(
23+
a: MutableSequence[_T],
24+
x: _T,
25+
lo: int = ...,
26+
hi: Optional[int] = ...,
27+
*,
28+
key: Optional[Callable[[_T], SupportsLessThan]] = ...,
29+
) -> None: ...
30+
31+
else:
32+
def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> int: ...
33+
def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> int: ...
34+
def insort_left(a: MutableSequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> None: ...
35+
def insort_right(a: MutableSequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> None: ...

stdlib/@python2/_codecs.pyi

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import codecs
2+
import sys
3+
from typing import Any, Callable, Dict, Optional, Text, Tuple, Union
4+
5+
# For convenience:
6+
_Handler = Callable[[Exception], Tuple[Text, int]]
7+
_String = Union[bytes, str]
8+
_Errors = Union[str, Text, None]
9+
if sys.version_info >= (3, 0):
10+
_Decodable = bytes
11+
_Encodable = str
12+
else:
13+
_Decodable = Union[bytes, Text]
14+
_Encodable = Union[bytes, Text]
15+
16+
# This type is not exposed; it is defined in unicodeobject.c
17+
class _EncodingMap(object):
18+
def size(self) -> int: ...
19+
20+
_MapT = Union[Dict[int, int], _EncodingMap]
21+
22+
def register(__search_function: Callable[[str], Any]) -> None: ...
23+
def register_error(__errors: Union[str, Text], __handler: _Handler) -> None: ...
24+
def lookup(__encoding: Union[str, Text]) -> codecs.CodecInfo: ...
25+
def lookup_error(__name: Union[str, Text]) -> _Handler: ...
26+
def decode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
27+
def encode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
28+
def charmap_build(__map: Text) -> _MapT: ...
29+
def ascii_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ...
30+
def ascii_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
31+
32+
if sys.version_info < (3, 2):
33+
def charbuffer_encode(__data: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
34+
35+
def charmap_decode(__data: _Decodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[Text, int]: ...
36+
def charmap_encode(__str: _Encodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ...
37+
def escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[str, int]: ...
38+
def escape_encode(__data: bytes, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
39+
def latin_1_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ...
40+
def latin_1_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
41+
def raw_unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
42+
def raw_unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
43+
def readbuffer_encode(__data: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
44+
def unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
45+
def unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
46+
47+
if sys.version_info < (3, 8):
48+
def unicode_internal_decode(__obj: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
49+
def unicode_internal_encode(__obj: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
50+
51+
def utf_16_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
52+
def utf_16_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
53+
def utf_16_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
54+
def utf_16_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ...
55+
def utf_16_ex_decode(
56+
__data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ...
57+
) -> Tuple[Text, int, int]: ...
58+
def utf_16_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
59+
def utf_16_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
60+
def utf_32_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
61+
def utf_32_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
62+
def utf_32_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
63+
def utf_32_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ...
64+
def utf_32_ex_decode(
65+
__data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ...
66+
) -> Tuple[Text, int, int]: ...
67+
def utf_32_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
68+
def utf_32_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
69+
def utf_7_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
70+
def utf_7_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
71+
def utf_8_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
72+
def utf_8_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
73+
74+
if sys.platform == "win32":
75+
def mbcs_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
76+
def mbcs_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
77+
if sys.version_info >= (3, 0):
78+
def code_page_decode(__codepage: int, __data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
79+
def code_page_encode(__code_page: int, __str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
80+
if sys.version_info >= (3, 6):
81+
def oem_decode(__data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
82+
def oem_encode(__str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

stdlib/@python2/_csv.pyi

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
from typing import Any, Iterable, Iterator, List, Optional, Protocol, Sequence, Text, Type, Union
3+
4+
QUOTE_ALL: int
5+
QUOTE_MINIMAL: int
6+
QUOTE_NONE: int
7+
QUOTE_NONNUMERIC: int
8+
9+
class Error(Exception): ...
10+
11+
class Dialect:
12+
delimiter: str
13+
quotechar: Optional[str]
14+
escapechar: Optional[str]
15+
doublequote: bool
16+
skipinitialspace: bool
17+
lineterminator: str
18+
quoting: int
19+
strict: int
20+
def __init__(self) -> None: ...
21+
22+
_DialectLike = Union[str, Dialect, Type[Dialect]]
23+
24+
class _reader(Iterator[List[str]]):
25+
dialect: Dialect
26+
line_num: int
27+
if sys.version_info >= (3, 0):
28+
def __next__(self) -> List[str]: ...
29+
else:
30+
def next(self) -> List[str]: ...
31+
32+
class _writer:
33+
dialect: Dialect
34+
35+
if sys.version_info >= (3, 5):
36+
def writerow(self, row: Iterable[Any]) -> Any: ...
37+
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
38+
else:
39+
def writerow(self, row: Sequence[Any]) -> Any: ...
40+
def writerows(self, rows: Iterable[Sequence[Any]]) -> None: ...
41+
42+
class _Writer(Protocol):
43+
def write(self, s: str) -> Any: ...
44+
45+
def writer(csvfile: _Writer, dialect: _DialectLike = ..., **fmtparams: Any) -> _writer: ...
46+
def reader(csvfile: Iterable[Text], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ...
47+
def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ...
48+
def unregister_dialect(name: str) -> None: ...
49+
def get_dialect(name: str) -> Dialect: ...
50+
def list_dialects() -> List[str]: ...
51+
def field_size_limit(new_limit: int = ...) -> int: ...

0 commit comments

Comments
 (0)