Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,13 @@ To automatically check your code before committing, copy the file
### Standard library stubs

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

The `stdlib/@python2` subdirectory contains Python 2-only stubs,
both for modules that must be kept different for Python 2 and 3, like
`builtins.pyi`, and for modules that only existed in Python 2, like
`ConfigParser.pyi`. The latter group of modules are not listed in
`VERSIONS`.

Note that if a package is present in `@python2`, any stub in the main
`stdlib` directory should be ignored when looking for Python 2 stubs. For
example, typeshed contains files `stdlib/@python2/collections.pyi` and
`stdlib/collections/abc.pyi`. A client looking for stubs for
`collections.abc` in Python 2 should not pick up the latter file, but
instead report that the module does not exist.
Stubs for Python 2 are available in the `stdlib/@python2` subdirectory.
Modules that are only available for Python 2 are not listed in `VERSIONS`.

### Third-party library stubs

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

When a third party stub is
Expand Down
26 changes: 26 additions & 0 deletions stdlib/@python2/__future__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
from typing import List

class _Feature:
def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ...
def getOptionalRelease(self) -> sys._version_info: ...
def getMandatoryRelease(self) -> sys._version_info: ...
compiler_flag: int

absolute_import: _Feature
division: _Feature
generators: _Feature
nested_scopes: _Feature
print_function: _Feature
unicode_literals: _Feature
with_statement: _Feature
if sys.version_info >= (3, 0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These Python 3 version checks might be worth removing at some point, at least if we can script it easily.

barry_as_FLUFL: _Feature

if sys.version_info >= (3, 5):
generator_stop: _Feature

if sys.version_info >= (3, 7):
annotations: _Feature

all_feature_names: List[str] # undocumented
3 changes: 3 additions & 0 deletions stdlib/@python2/__main__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def __getattr__(name: str) -> Any: ...
35 changes: 35 additions & 0 deletions stdlib/@python2/_bisect.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys
from _typeshed import SupportsLessThan
from typing import Callable, MutableSequence, Optional, Sequence, TypeVar

_T = TypeVar("_T")

if sys.version_info >= (3, 10):
def bisect_left(
a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ..., *, key: Optional[Callable[[_T], SupportsLessThan]] = ...
) -> int: ...
def bisect_right(
a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ..., *, key: Optional[Callable[[_T], SupportsLessThan]] = ...
) -> int: ...
def insort_left(
a: MutableSequence[_T],
x: _T,
lo: int = ...,
hi: Optional[int] = ...,
*,
key: Optional[Callable[[_T], SupportsLessThan]] = ...,
) -> None: ...
def insort_right(
a: MutableSequence[_T],
x: _T,
lo: int = ...,
hi: Optional[int] = ...,
*,
key: Optional[Callable[[_T], SupportsLessThan]] = ...,
) -> None: ...

else:
def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> int: ...
def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> int: ...
def insort_left(a: MutableSequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> None: ...
def insort_right(a: MutableSequence[_T], x: _T, lo: int = ..., hi: Optional[int] = ...) -> None: ...
82 changes: 82 additions & 0 deletions stdlib/@python2/_codecs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import codecs
import sys
from typing import Any, Callable, Dict, Optional, Text, Tuple, Union

# For convenience:
_Handler = Callable[[Exception], Tuple[Text, int]]
_String = Union[bytes, str]
_Errors = Union[str, Text, None]
if sys.version_info >= (3, 0):
_Decodable = bytes
_Encodable = str
else:
_Decodable = Union[bytes, Text]
_Encodable = Union[bytes, Text]

# This type is not exposed; it is defined in unicodeobject.c
class _EncodingMap(object):
def size(self) -> int: ...

_MapT = Union[Dict[int, int], _EncodingMap]

def register(__search_function: Callable[[str], Any]) -> None: ...
def register_error(__errors: Union[str, Text], __handler: _Handler) -> None: ...
def lookup(__encoding: Union[str, Text]) -> codecs.CodecInfo: ...
def lookup_error(__name: Union[str, Text]) -> _Handler: ...
def decode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
def encode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ...
def charmap_build(__map: Text) -> _MapT: ...
def ascii_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ...
def ascii_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

if sys.version_info < (3, 2):
def charbuffer_encode(__data: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

def charmap_decode(__data: _Decodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[Text, int]: ...
def charmap_encode(__str: _Encodable, __errors: _Errors = ..., __mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ...
def escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[str, int]: ...
def escape_encode(__data: bytes, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def latin_1_decode(__data: _Decodable, __errors: _Errors = ...) -> Tuple[Text, int]: ...
def latin_1_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def raw_unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
def raw_unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def readbuffer_encode(__data: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def unicode_escape_decode(__data: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
def unicode_escape_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

if sys.version_info < (3, 8):
def unicode_internal_decode(__obj: _String, __errors: _Errors = ...) -> Tuple[Text, int]: ...
def unicode_internal_encode(__obj: _String, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

def utf_16_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_16_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_16_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_16_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_16_ex_decode(
__data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ...
) -> Tuple[Text, int, int]: ...
def utf_16_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_16_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_32_be_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_32_be_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_32_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_32_encode(__str: _Encodable, __errors: _Errors = ..., __byteorder: int = ...) -> Tuple[bytes, int]: ...
def utf_32_ex_decode(
__data: _Decodable, __errors: _Errors = ..., __byteorder: int = ..., __final: int = ...
) -> Tuple[Text, int, int]: ...
def utf_32_le_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_32_le_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_7_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_7_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
def utf_8_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def utf_8_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...

if sys.platform == "win32":
def mbcs_decode(__data: _Decodable, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def mbcs_encode(__str: _Encodable, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
if sys.version_info >= (3, 0):
def code_page_decode(__codepage: int, __data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def code_page_encode(__code_page: int, __str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
if sys.version_info >= (3, 6):
def oem_decode(__data: bytes, __errors: _Errors = ..., __final: int = ...) -> Tuple[Text, int]: ...
def oem_encode(__str: Text, __errors: _Errors = ...) -> Tuple[bytes, int]: ...
51 changes: 51 additions & 0 deletions stdlib/@python2/_csv.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys
from typing import Any, Iterable, Iterator, List, Optional, Protocol, Sequence, Text, Type, Union

QUOTE_ALL: int
QUOTE_MINIMAL: int
QUOTE_NONE: int
QUOTE_NONNUMERIC: int

class Error(Exception): ...

class Dialect:
delimiter: str
quotechar: Optional[str]
escapechar: Optional[str]
doublequote: bool
skipinitialspace: bool
lineterminator: str
quoting: int
strict: int
def __init__(self) -> None: ...

_DialectLike = Union[str, Dialect, Type[Dialect]]

class _reader(Iterator[List[str]]):
dialect: Dialect
line_num: int
if sys.version_info >= (3, 0):
def __next__(self) -> List[str]: ...
else:
def next(self) -> List[str]: ...

class _writer:
dialect: Dialect

if sys.version_info >= (3, 5):
def writerow(self, row: Iterable[Any]) -> Any: ...
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
else:
def writerow(self, row: Sequence[Any]) -> Any: ...
def writerows(self, rows: Iterable[Sequence[Any]]) -> None: ...

class _Writer(Protocol):
def write(self, s: str) -> Any: ...

def writer(csvfile: _Writer, dialect: _DialectLike = ..., **fmtparams: Any) -> _writer: ...
def reader(csvfile: Iterable[Text], dialect: _DialectLike = ..., **fmtparams: Any) -> _reader: ...
def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ...
def unregister_dialect(name: str) -> None: ...
def get_dialect(name: str) -> Dialect: ...
def list_dialects() -> List[str]: ...
def field_size_limit(new_limit: int = ...) -> int: ...
Loading