mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Sync with typeshed @ 1b37ca4297b0f0b6362b68ed37c88a6e6c5f1d8d
Excluding https://github.com/python/typeshed/pull/2480
This commit is contained in:
@@ -20,4 +20,4 @@ ignore = F401, F403, F405, F811, E127, E128, E301, E302, E305, E501, E701, E704,
|
||||
# A nice future improvement would be to provide separate .flake8
|
||||
# configurations for Python 2 and Python 3 files.
|
||||
builtins = StandardError,apply,basestring,buffer,cmp,coerce,execfile,file,intern,long,raw_input,reduce,reload,unichr,unicode,xrange
|
||||
exclude = .venv*,@*
|
||||
exclude = .venv*,@*,.git
|
||||
|
||||
@@ -6,20 +6,19 @@ matrix:
|
||||
- python: "3.6-dev"
|
||||
env: TEST_CMD="flake8"
|
||||
- python: "3.6"
|
||||
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"
|
||||
- python: "3.5-dev"
|
||||
env: TEST_CMD="./tests/mypy_selftest.py"
|
||||
- python: "3.5"
|
||||
env: TEST_CMD="./tests/mypy_test.py"
|
||||
- python: "3.4"
|
||||
env: TEST_CMD="./tests/check_consistent.py"
|
||||
- python: "2.7"
|
||||
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"
|
||||
sudo: true
|
||||
|
||||
install:
|
||||
# pytype needs py-2.7, mypy needs py-3.3+. Additional logic in runtests.py
|
||||
# pytype needs py-3.6, mypy needs py-3.3+. Additional logic in runtests.py
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.6-dev' ]]; then pip install -r requirements-tests-py3.txt; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install -r requirements-tests-py3.txt; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast; fi
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -r requirements-tests-py2.txt; wget https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/14.04/x86_64/python-3.6.tar.bz2; sudo tar xjf python-3.6.tar.bz2 --directory /; fi
|
||||
|
||||
script:
|
||||
- $TEST_CMD
|
||||
|
||||
@@ -85,6 +85,7 @@ At present the core developers are (alphabetically):
|
||||
* Ivan Levkivskyi (@ilevkivskyi)
|
||||
* Matthias Kramm (@matthiaskramm)
|
||||
* Greg Price (@gnprice)
|
||||
* Sebastian Rittau (@srittau)
|
||||
* Guido van Rossum (@gvanrossum)
|
||||
* Jelle Zijlstra (@JelleZijlstra)
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ $ source .venv3/bin/activate
|
||||
(.venv3)$ pip3 install -r requirements-tests-py3.txt
|
||||
```
|
||||
This will install mypy (you need the latest master branch from GitHub),
|
||||
typed-ast, and flake8. You can then run mypy tests and flake8 tests by
|
||||
invoking:
|
||||
typed-ast, flake8, and pytype. You can then run mypy, flake8, and pytype tests
|
||||
by invoking:
|
||||
```
|
||||
(.venv3)$ python3 tests/mypy_test.py
|
||||
...
|
||||
@@ -123,21 +123,13 @@ invoking:
|
||||
...
|
||||
(.venv3)$ flake8
|
||||
...
|
||||
(.venv3)$ python3 tests/pytype_test.py
|
||||
...
|
||||
```
|
||||
(Note that flake8 only works with Python 3.6 or higher.)
|
||||
|
||||
To run the pytype tests, you need a separate virtual environment with
|
||||
Python 2.7, and a Python 3.6 interpreter somewhere you can point to. Run:
|
||||
```
|
||||
$ virtualenv --python=python2.7 .venv2
|
||||
$ source .venv2/bin/activate
|
||||
(.venv2)$ pip install -r requirements-tests-py2.txt
|
||||
```
|
||||
This will install pytype from its GitHub repo. You can then run pytype
|
||||
tests by running:
|
||||
```
|
||||
(.venv2)$ python tests/pytype_test.py --python36-exe=/path/to/python3.6
|
||||
```
|
||||
Note that flake8 only works with Python 3.6 or higher, and that to run the
|
||||
pytype tests, you will need Python 2.7 and Python 3.6 interpreters. Pytype will
|
||||
find these automatically if they're in `PATH`, but otherwise you must point to
|
||||
them with the `--python27-exe` and `--python36-exe` arguments, respectively.
|
||||
|
||||
For mypy, if you are in the typeshed repo that is submodule of the
|
||||
mypy repo (so `..` refers to the mypy repo), there's a shortcut to run
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pytype>=2018.6.19
|
||||
@@ -3,3 +3,4 @@ typed-ast>=1.0.4
|
||||
flake8==3.5.0
|
||||
flake8-bugbear==18.2.0
|
||||
flake8-pyi>=18.3.1
|
||||
pytype>=2018.9.19
|
||||
|
||||
@@ -517,7 +517,6 @@ class slice(object):
|
||||
|
||||
class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ...
|
||||
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __contains__(self, x: object) -> bool: ...
|
||||
@overload
|
||||
@@ -737,11 +736,20 @@ def divmod(a: int, b: int) -> Tuple[int, int]: ...
|
||||
def divmod(a: float, b: float) -> Tuple[float, float]: ...
|
||||
def exit(code: Any = ...) -> NoReturn: ...
|
||||
@overload
|
||||
def filter(function: None,
|
||||
iterable: Iterable[Optional[_T]]) -> List[_T]: ...
|
||||
def filter(__function: Callable[[AnyStr], Any], # type: ignore
|
||||
__iterable: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def filter(function: Callable[[_T], Any],
|
||||
iterable: Iterable[_T]) -> List[_T]: ...
|
||||
def filter(__function: None, # type: ignore
|
||||
__iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ...
|
||||
@overload
|
||||
def filter(__function: Callable[[_T], Any], # type: ignore
|
||||
__iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ...
|
||||
@overload
|
||||
def filter(__function: None,
|
||||
__iterable: Iterable[Optional[_T]]) -> List[_T]: ...
|
||||
@overload
|
||||
def filter(__function: Callable[[_T], Any],
|
||||
__iterable: Iterable[_T]) -> List[_T]: ...
|
||||
def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode
|
||||
def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ...
|
||||
def hasattr(o: Any, name: unicode) -> bool: ...
|
||||
@@ -966,7 +974,7 @@ class memoryview(Sized, Container[bytes]):
|
||||
class BaseException(object):
|
||||
args = ... # type: Tuple[Any, ...]
|
||||
message = ... # type: Any
|
||||
def __init__(self, *args: object, **kwargs: object) -> None: ...
|
||||
def __init__(self, *args: object) -> None: ...
|
||||
def __getitem__(self, i: int) -> Any: ...
|
||||
def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ...
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ class TextIOWrapper(_TextIOBase):
|
||||
write_through: bool = ...) -> None: ...
|
||||
|
||||
def open(file: Union[str, unicode, int],
|
||||
mode: unicode = ...,
|
||||
mode: Text = ...,
|
||||
buffering: int = ...,
|
||||
encoding: Optional[Text] = ...,
|
||||
errors: Optional[Text] = ...,
|
||||
|
||||
@@ -517,7 +517,6 @@ class slice(object):
|
||||
|
||||
class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ...
|
||||
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __contains__(self, x: object) -> bool: ...
|
||||
@overload
|
||||
@@ -737,11 +736,20 @@ def divmod(a: int, b: int) -> Tuple[int, int]: ...
|
||||
def divmod(a: float, b: float) -> Tuple[float, float]: ...
|
||||
def exit(code: Any = ...) -> NoReturn: ...
|
||||
@overload
|
||||
def filter(function: None,
|
||||
iterable: Iterable[Optional[_T]]) -> List[_T]: ...
|
||||
def filter(__function: Callable[[AnyStr], Any], # type: ignore
|
||||
__iterable: AnyStr) -> AnyStr: ...
|
||||
@overload
|
||||
def filter(function: Callable[[_T], Any],
|
||||
iterable: Iterable[_T]) -> List[_T]: ...
|
||||
def filter(__function: None, # type: ignore
|
||||
__iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ...
|
||||
@overload
|
||||
def filter(__function: Callable[[_T], Any], # type: ignore
|
||||
__iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ...
|
||||
@overload
|
||||
def filter(__function: None,
|
||||
__iterable: Iterable[Optional[_T]]) -> List[_T]: ...
|
||||
@overload
|
||||
def filter(__function: Callable[[_T], Any],
|
||||
__iterable: Iterable[_T]) -> List[_T]: ...
|
||||
def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode
|
||||
def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ...
|
||||
def hasattr(o: Any, name: unicode) -> bool: ...
|
||||
@@ -966,7 +974,7 @@ class memoryview(Sized, Container[bytes]):
|
||||
class BaseException(object):
|
||||
args = ... # type: Tuple[Any, ...]
|
||||
message = ... # type: Any
|
||||
def __init__(self, *args: object, **kwargs: object) -> None: ...
|
||||
def __init__(self, *args: object) -> None: ...
|
||||
def __getitem__(self, i: int) -> Any: ...
|
||||
def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ...
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
# Stubs for collections
|
||||
|
||||
# Based on http://docs.python.org/2.7/library/collections.html
|
||||
|
||||
# These are not exported.
|
||||
import typing
|
||||
from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible
|
||||
|
||||
# These are exported.
|
||||
@@ -31,7 +26,7 @@ _KT = TypeVar('_KT')
|
||||
_VT = TypeVar('_VT')
|
||||
|
||||
# namedtuple is special-cased in the type checker; the initializer is ignored.
|
||||
def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]], *,
|
||||
def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]],
|
||||
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
|
||||
|
||||
class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
|
||||
|
||||
@@ -163,6 +163,12 @@ class MutableSequence(Sequence[_T], Generic[_T]):
|
||||
def insert(self, index: int, object: _T) -> None: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __getitem__(self, i: int) -> _T: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __getitem__(self, s: slice) -> MutableSequence[_T]: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __setitem__(self, i: int, o: _T) -> None: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
@@ -352,17 +358,23 @@ class TextIO(IO[unicode]):
|
||||
class ByteString(Sequence[int], metaclass=ABCMeta): ...
|
||||
|
||||
class Match(Generic[AnyStr]):
|
||||
pos = 0
|
||||
endpos = 0
|
||||
lastindex = 0
|
||||
lastgroup = ... # type: AnyStr
|
||||
string = ... # type: AnyStr
|
||||
pos: int
|
||||
endpos: int
|
||||
lastindex: Optional[int]
|
||||
string: AnyStr
|
||||
|
||||
# The regular expression object whose match() or search() method produced
|
||||
# this match instance.
|
||||
re = ... # type: Pattern[AnyStr]
|
||||
# this match instance. This should not be Pattern[AnyStr] because the type
|
||||
# of the pattern is independent of the type of the matched string in
|
||||
# Python 2. Strictly speaking Match should be generic over AnyStr twice:
|
||||
# once for the type of the pattern and once for the type of the matched
|
||||
# string.
|
||||
re: Pattern[Any]
|
||||
# Can be None if there are no groups or if the last group was unnamed;
|
||||
# otherwise matches the type of the pattern.
|
||||
lastgroup: Optional[Any]
|
||||
|
||||
def expand(self, template: AnyStr) -> AnyStr: ...
|
||||
def expand(self, template: Union[str, Text]) -> Any: ...
|
||||
|
||||
@overload
|
||||
def group(self, group1: int = ...) -> AnyStr: ...
|
||||
@@ -370,53 +382,64 @@ class Match(Generic[AnyStr]):
|
||||
def group(self, group1: str) -> AnyStr: ...
|
||||
@overload
|
||||
def group(self, group1: int, group2: int,
|
||||
*groups: int) -> Sequence[AnyStr]: ...
|
||||
*groups: int) -> Tuple[AnyStr, ...]: ...
|
||||
@overload
|
||||
def group(self, group1: str, group2: str,
|
||||
*groups: str) -> Sequence[AnyStr]: ...
|
||||
*groups: str) -> Tuple[AnyStr, ...]: ...
|
||||
|
||||
def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ...
|
||||
def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ...
|
||||
def groups(self, default: AnyStr = ...) -> Tuple[AnyStr, ...]: ...
|
||||
def groupdict(self, default: AnyStr = ...) -> Dict[str, AnyStr]: ...
|
||||
def start(self, group: Union[int, str] = ...) -> int: ...
|
||||
def end(self, group: Union[int, str] = ...) -> int: ...
|
||||
def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ...
|
||||
|
||||
# We need a second TypeVar with the same definition as AnyStr, because
|
||||
# Pattern is generic over AnyStr (determining the type of its .pattern
|
||||
# attribute), but at the same time its methods take either bytes or
|
||||
# Text and return the same type, regardless of the type of the pattern.
|
||||
_AnyStr2 = TypeVar('_AnyStr2', bytes, Text)
|
||||
|
||||
class Pattern(Generic[AnyStr]):
|
||||
flags = 0
|
||||
groupindex = 0
|
||||
groups = 0
|
||||
pattern = ... # type: AnyStr
|
||||
flags: int
|
||||
groupindex: Dict[AnyStr, int]
|
||||
groups: int
|
||||
pattern: AnyStr
|
||||
|
||||
def search(self, string: AnyStr, pos: int = ...,
|
||||
endpos: int = ...) -> Optional[Match[AnyStr]]: ...
|
||||
def match(self, string: AnyStr, pos: int = ...,
|
||||
endpos: int = ...) -> Optional[Match[AnyStr]]: ...
|
||||
def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ...
|
||||
def findall(self, string: AnyStr, pos: int = ...,
|
||||
endpos: int = ...) -> list[Any]: ...
|
||||
def finditer(self, string: AnyStr, pos: int = ...,
|
||||
endpos: int = ...) -> Iterator[Match[AnyStr]]: ...
|
||||
def search(self, string: _AnyStr2, pos: int = ...,
|
||||
endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
|
||||
def match(self, string: _AnyStr2, pos: int = ...,
|
||||
endpos: int = ...) -> Optional[Match[_AnyStr2]]: ...
|
||||
def split(self, string: _AnyStr2, maxsplit: int = ...) -> List[_AnyStr2]: ...
|
||||
# Returns either a list of _AnyStr2 or a list of tuples, depending on
|
||||
# whether there are groups in the pattern.
|
||||
def findall(self, string: Union[bytes, Text], pos: int = ...,
|
||||
endpos: int = ...) -> List[Any]: ...
|
||||
def finditer(self, string: _AnyStr2, pos: int = ...,
|
||||
endpos: int = ...) -> Iterator[Match[_AnyStr2]]: ...
|
||||
|
||||
@overload
|
||||
def sub(self, repl: AnyStr, string: AnyStr,
|
||||
count: int = ...) -> AnyStr: ...
|
||||
def sub(self, repl: _AnyStr2, string: _AnyStr2,
|
||||
count: int = ...) -> _AnyStr2: ...
|
||||
@overload
|
||||
def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,
|
||||
count: int = ...) -> AnyStr: ...
|
||||
def sub(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2,
|
||||
count: int = ...) -> _AnyStr2: ...
|
||||
|
||||
@overload
|
||||
def subn(self, repl: AnyStr, string: AnyStr,
|
||||
count: int = ...) -> Tuple[AnyStr, int]: ...
|
||||
def subn(self, repl: _AnyStr2, string: _AnyStr2,
|
||||
count: int = ...) -> Tuple[_AnyStr2, int]: ...
|
||||
@overload
|
||||
def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr,
|
||||
count: int = ...) -> Tuple[AnyStr, int]: ...
|
||||
def subn(self, repl: Callable[[Match[_AnyStr2]], _AnyStr2], string: _AnyStr2,
|
||||
count: int = ...) -> Tuple[_AnyStr2, int]: ...
|
||||
|
||||
# Functions
|
||||
|
||||
def get_type_hints(obj: Callable, globalns: Optional[dict[Text, Any]] = ...,
|
||||
localns: Optional[dict[Text, Any]] = ...) -> None: ...
|
||||
|
||||
@overload
|
||||
def cast(tp: Type[_T], obj: Any) -> _T: ...
|
||||
@overload
|
||||
def cast(tp: str, obj: Any) -> Any: ...
|
||||
|
||||
# Type constructors
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ class _ActionsContainer:
|
||||
help: Optional[_Text] = ...,
|
||||
metavar: Union[_Text, Tuple[_Text, ...]] = ...,
|
||||
dest: Optional[_Text] = ...,
|
||||
version: _Text = ...) -> Action: ...
|
||||
version: _Text = ...,
|
||||
**kwargs: Any) -> Action: ...
|
||||
def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ...
|
||||
def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ...
|
||||
def _add_action(self, action: _ActionT) -> _ActionT: ...
|
||||
@@ -122,15 +123,29 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
add_help: bool = ...) -> None: ...
|
||||
def parse_args(self, args: Optional[Sequence[_Text]] = ...,
|
||||
namespace: Optional[Namespace] = ...) -> Namespace: ...
|
||||
def add_subparsers(self, title: _Text = ...,
|
||||
description: Optional[_Text] = ...,
|
||||
prog: _Text = ...,
|
||||
parser_class: Type[ArgumentParser] = ...,
|
||||
action: Type[Action] = ...,
|
||||
option_string: _Text = ...,
|
||||
dest: Optional[_Text] = ...,
|
||||
help: Optional[_Text] = ...,
|
||||
metavar: Optional[_Text] = ...) -> _SubParsersAction: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
def add_subparsers(self, title: _Text = ...,
|
||||
description: Optional[_Text] = ...,
|
||||
prog: _Text = ...,
|
||||
parser_class: Type[ArgumentParser] = ...,
|
||||
action: Type[Action] = ...,
|
||||
option_string: _Text = ...,
|
||||
dest: Optional[_Text] = ...,
|
||||
required: bool = ...,
|
||||
help: Optional[_Text] = ...,
|
||||
metavar: Optional[_Text] = ...) -> _SubParsersAction: ...
|
||||
else:
|
||||
def add_subparsers(self, title: _Text = ...,
|
||||
description: Optional[_Text] = ...,
|
||||
prog: _Text = ...,
|
||||
parser_class: Type[ArgumentParser] = ...,
|
||||
action: Type[Action] = ...,
|
||||
option_string: _Text = ...,
|
||||
dest: Optional[_Text] = ...,
|
||||
help: Optional[_Text] = ...,
|
||||
metavar: Optional[_Text] = ...) -> _SubParsersAction: ...
|
||||
|
||||
def print_usage(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def print_help(self, file: Optional[IO[str]] = ...) -> None: ...
|
||||
def format_usage(self) -> str: ...
|
||||
|
||||
@@ -43,6 +43,9 @@ class date:
|
||||
def today(cls) -> date: ...
|
||||
@classmethod
|
||||
def fromordinal(cls, n: int) -> date: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls, date_string: str) -> date: ...
|
||||
|
||||
@property
|
||||
def year(self) -> int: ...
|
||||
@@ -80,8 +83,12 @@ class time:
|
||||
max: ClassVar[time]
|
||||
resolution: ClassVar[timedelta]
|
||||
|
||||
def __init__(self, hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ...,
|
||||
tzinfo: Optional[tzinfo] = ...) -> None: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def __init__(self, hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ..., *, fold: int = ...) -> None: ...
|
||||
else:
|
||||
def __init__(self, hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ...,
|
||||
tzinfo: Optional[_tzinfo] = ...) -> None: ...
|
||||
|
||||
@property
|
||||
def hour(self) -> int: ...
|
||||
@@ -103,6 +110,9 @@ class time:
|
||||
def __gt__(self, other: time) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def isoformat(self) -> str: ...
|
||||
if sys.version_info >= (3, 7):
|
||||
@classmethod
|
||||
def fromisoformat(cls, time_string: str) -> time: ...
|
||||
def strftime(self, fmt: _Text) -> str: ...
|
||||
if sys.version_info >= (3,):
|
||||
def __format__(self, fmt: str) -> str: ...
|
||||
@@ -127,9 +137,14 @@ class timedelta(SupportsAbs[timedelta]):
|
||||
max: ClassVar[timedelta]
|
||||
resolution: ClassVar[timedelta]
|
||||
|
||||
def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ...,
|
||||
milliseconds: float = ..., minutes: float = ..., hours: float = ...,
|
||||
weeks: float = ...) -> None: ...
|
||||
if sys.version_info >= (3, 6):
|
||||
def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ...,
|
||||
milliseconds: float = ..., minutes: float = ..., hours: float = ...,
|
||||
weeks: float = ..., *, fold: int = ...) -> None: ...
|
||||
else:
|
||||
def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ...,
|
||||
milliseconds: float = ..., minutes: float = ..., hours: float = ...,
|
||||
weeks: float = ...) -> None: ...
|
||||
|
||||
@property
|
||||
def days(self) -> int: ...
|
||||
@@ -170,8 +185,7 @@ class timedelta(SupportsAbs[timedelta]):
|
||||
def __gt__(self, other: timedelta) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class datetime:
|
||||
# TODO: Is a subclass of date, but this would make some types incompatible.
|
||||
class datetime(date):
|
||||
min: ClassVar[datetime]
|
||||
max: ClassVar[datetime]
|
||||
resolution: ClassVar[timedelta]
|
||||
@@ -179,11 +193,11 @@ class datetime:
|
||||
if sys.version_info >= (3, 6):
|
||||
def __init__(self, year: int, month: int, day: int, hour: int = ...,
|
||||
minute: int = ..., second: int = ..., microsecond: int = ...,
|
||||
tzinfo: Optional[tzinfo] = ..., *, fold: int = ...) -> None: ...
|
||||
tzinfo: Optional[_tzinfo] = ..., *, fold: int = ...) -> None: ...
|
||||
else:
|
||||
def __init__(self, year: int, month: int, day: int, hour: int = ...,
|
||||
minute: int = ..., second: int = ..., microsecond: int = ...,
|
||||
tzinfo: Optional[tzinfo] = ...) -> None: ...
|
||||
tzinfo: Optional[_tzinfo] = ...) -> None: ...
|
||||
|
||||
@property
|
||||
def year(self) -> int: ...
|
||||
@@ -261,15 +275,15 @@ class datetime:
|
||||
def utcoffset(self) -> Optional[timedelta]: ...
|
||||
def tzname(self) -> Optional[str]: ...
|
||||
def dst(self) -> Optional[int]: ...
|
||||
def __le__(self, other: datetime) -> bool: ...
|
||||
def __lt__(self, other: datetime) -> bool: ...
|
||||
def __ge__(self, other: datetime) -> bool: ...
|
||||
def __gt__(self, other: datetime) -> bool: ...
|
||||
def __le__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __lt__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __ge__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __gt__(self, other: datetime) -> bool: ... # type: ignore
|
||||
def __add__(self, other: timedelta) -> datetime: ...
|
||||
@overload
|
||||
def __sub__(self, other: datetime) -> timedelta: ...
|
||||
@overload
|
||||
def __sub__(self, other: timedelta) -> datetime: ...
|
||||
@overload # type: ignore
|
||||
def __sub__(self, other: datetime) -> timedelta: ... # type: ignore
|
||||
@overload # type: ignore
|
||||
def __sub__(self, other: timedelta) -> datetime: ... # type: ignore
|
||||
def __hash__(self) -> int: ...
|
||||
def weekday(self) -> int: ...
|
||||
def isoweekday(self) -> int: ...
|
||||
|
||||
@@ -7,7 +7,7 @@ import sys
|
||||
|
||||
from typing import (
|
||||
List, Iterable, Callable, Any, Tuple, Sequence, NamedTuple, IO,
|
||||
AnyStr, Optional, Union, Set, TypeVar, overload, Type, Protocol
|
||||
AnyStr, Optional, Union, Set, TypeVar, overload, Type, Protocol, Text
|
||||
)
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
@@ -23,7 +23,7 @@ elif sys.version_info >= (3,):
|
||||
_AnyPath = str
|
||||
_PathReturn = str
|
||||
else:
|
||||
_Path = unicode
|
||||
_Path = Text
|
||||
_AnyStr = TypeVar("_AnyStr", str, unicode)
|
||||
_AnyPath = TypeVar("_AnyPath", str, unicode)
|
||||
_PathReturn = Type[None]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# see: http://nullege.com/codes/search/socket
|
||||
# adapted for Python 2.7 by Michal Pokorny
|
||||
import sys
|
||||
from typing import Any, Iterable, Tuple, List, Optional, Union, overload, TypeVar
|
||||
from typing import Any, Iterable, Tuple, List, Optional, Union, overload, TypeVar, Text
|
||||
|
||||
_WriteBuffer = Union[bytearray, memoryview]
|
||||
|
||||
@@ -549,12 +549,12 @@ class socket:
|
||||
...
|
||||
def recv(self, bufsize: int, flags: int = ...) -> bytes: ...
|
||||
|
||||
# return type is an address
|
||||
def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ...
|
||||
# Any in return type is an address
|
||||
def recvfrom(self, bufsize: int, flags: int = ...) -> Tuple[bytes, Any]: ...
|
||||
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int,
|
||||
flags: int = ...) -> Any: ...
|
||||
flags: int = ...) -> Tuple[int, Any]: ...
|
||||
def recv_into(self, buffer: _WriteBuffer, nbytes: int,
|
||||
flags: int = ...) -> Any: ...
|
||||
flags: int = ...) -> int: ...
|
||||
def send(self, data: bytes, flags: int = ...) -> int: ...
|
||||
def sendall(self, data: bytes, flags: int =...) -> None:
|
||||
... # return type: None on success
|
||||
@@ -579,13 +579,13 @@ class socket:
|
||||
# ----- functions -----
|
||||
def create_connection(address: Tuple[Optional[str], int],
|
||||
timeout: float = ...,
|
||||
source_address: Tuple[str, int] = ...) -> socket: ...
|
||||
source_address: Tuple[Union[bytearray, bytes, Text], int] = ...) -> socket: ...
|
||||
|
||||
# the 5th tuple item is an address
|
||||
# TODO the "Tuple[Any, ...]" should be "Union[Tuple[str, int], Tuple[str, int, int, int]]" but that triggers
|
||||
# https://github.com/python/mypy/issues/2509
|
||||
def getaddrinfo(
|
||||
host: Optional[str], port: Union[str, int, None], family: int = ...,
|
||||
host: Optional[Union[bytearray, bytes, Text]], port: Union[str, int, None], family: int = ...,
|
||||
socktype: int = ..., proto: int = ...,
|
||||
flags: int = ...) -> List[Tuple[int, int, int, str, Tuple[Any, ...]]]:
|
||||
...
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Filip Hron <filip.hron@gmail.com>
|
||||
# based heavily on Andrey Vlasovskikh's python-skeletons https://github.com/JetBrains/python-skeletons/blob/master/sqlite3.py
|
||||
|
||||
import os
|
||||
import sys
|
||||
from typing import Any, Callable, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union
|
||||
from datetime import date, time, datetime
|
||||
@@ -70,7 +71,16 @@ version = ... # type: str
|
||||
# TODO: adapt needs to get probed
|
||||
def adapt(obj, protocol, alternate): ...
|
||||
def complete_statement(sql: str) -> bool: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
if sys.version_info >= (3, 7):
|
||||
def connect(database: Union[bytes, Text, os.PathLike[Text]],
|
||||
timeout: float = ...,
|
||||
detect_types: int = ...,
|
||||
isolation_level: Optional[str] = ...,
|
||||
check_same_thread: bool = ...,
|
||||
factory: Optional[Type[Connection]] = ...,
|
||||
cached_statements: int = ...,
|
||||
uri: bool = ...) -> Connection: ...
|
||||
elif sys.version_info >= (3, 4):
|
||||
def connect(database: Union[bytes, Text],
|
||||
timeout: float = ...,
|
||||
detect_types: int = ...,
|
||||
@@ -152,16 +162,16 @@ class Cursor(Iterator[Any]):
|
||||
# TODO: Cursor class accepts exactly 1 argument
|
||||
# required type is sqlite3.Connection (which is imported as _Connection)
|
||||
# however, the name of the __init__ variable is unknown
|
||||
def __init__(self, *args, **kwargs): ...
|
||||
def close(self, *args, **kwargs): ...
|
||||
def __init__(self, *args, **kwargs) -> None: ...
|
||||
def close(self, *args, **kwargs) -> None: ...
|
||||
def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ...
|
||||
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]): ...
|
||||
def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]) -> Cursor: ...
|
||||
def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ...
|
||||
def fetchall(self) -> List[Any]: ...
|
||||
def fetchmany(self, size: Optional[int] = ...) -> List[Any]: ...
|
||||
def fetchone(self) -> Any: ...
|
||||
def setinputsizes(self, *args, **kwargs): ...
|
||||
def setoutputsize(self, *args, **kwargs): ...
|
||||
def setinputsizes(self, *args, **kwargs) -> None: ...
|
||||
def setoutputsize(self, *args, **kwargs) -> None: ...
|
||||
def __iter__(self) -> Cursor: ...
|
||||
if sys.version_info >= (3, 0):
|
||||
def __next__(self) -> Any: ...
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Stubs for uuid
|
||||
|
||||
import sys
|
||||
from typing import Tuple, Optional, Any
|
||||
from typing import Tuple, Optional, Any, Text
|
||||
|
||||
# Because UUID has properties called int and bytes we need to rename these temporarily.
|
||||
_Int = int
|
||||
@@ -9,7 +9,8 @@ _Bytes = bytes
|
||||
_FieldsType = Tuple[int, int, int, int, int, int]
|
||||
|
||||
class UUID:
|
||||
def __init__(self, hex: Optional[str] = ..., bytes: Optional[_Bytes] = ...,
|
||||
def __init__(self, hex: Optional[Text] = ...,
|
||||
bytes: Optional[_Bytes] = ...,
|
||||
bytes_le: Optional[_Bytes] = ...,
|
||||
fields: Optional[_FieldsType] = ...,
|
||||
int: Optional[_Int] = ...,
|
||||
|
||||
@@ -97,6 +97,20 @@ if sys.platform != 'win32':
|
||||
start_unix_server as start_unix_server,
|
||||
)
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
from asyncio.events import (
|
||||
get_running_loop as get_running_loop,
|
||||
)
|
||||
from asyncio.tasks import (
|
||||
all_tasks as all_tasks,
|
||||
create_task as create_task,
|
||||
current_task as current_task,
|
||||
)
|
||||
from asyncio.runners import (
|
||||
run as run,
|
||||
)
|
||||
|
||||
|
||||
# TODO: It should be possible to instantiate these classes, but mypy
|
||||
# currently disallows this.
|
||||
# See https://github.com/python/mypy/issues/1843
|
||||
|
||||
@@ -34,6 +34,7 @@ class TimerHandle(Handle):
|
||||
def __hash__(self) -> int: ...
|
||||
|
||||
class AbstractServer:
|
||||
sockets: Optional[List[socket]]
|
||||
def close(self) -> None: ...
|
||||
@coroutine
|
||||
def wait_closed(self) -> Generator[Any, None, None]: ...
|
||||
@@ -179,9 +180,10 @@ class AbstractEventLoop(metaclass=ABCMeta):
|
||||
def remove_signal_handler(self, sig: int) -> None: ...
|
||||
# Error handlers.
|
||||
@abstractmethod
|
||||
def set_exception_handler(self, handler: _ExceptionHandler) -> None: ...
|
||||
@abstractmethod
|
||||
def get_exception_handler(self) -> _ExceptionHandler: ...
|
||||
def set_exception_handler(self, handler: Optional[_ExceptionHandler]) -> None: ...
|
||||
if sys.version_info >= (3, 5):
|
||||
@abstractmethod
|
||||
def get_exception_handler(self) -> Optional[_ExceptionHandler]: ...
|
||||
@abstractmethod
|
||||
def default_exception_handler(self, context: _Context) -> None: ...
|
||||
@abstractmethod
|
||||
@@ -223,3 +225,6 @@ def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractCh
|
||||
|
||||
def _set_running_loop(loop: AbstractEventLoop) -> None: ...
|
||||
def _get_running_loop() -> AbstractEventLoop: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
def get_running_loop() -> AbstractEventLoop: ...
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
from asyncio import transports
|
||||
from typing import List, Text, Tuple, Union
|
||||
from typing import List, Optional, Text, Tuple, Union
|
||||
|
||||
__all__: List[str]
|
||||
|
||||
|
||||
class BaseProtocol:
|
||||
def connection_made(self, transport: transports.BaseTransport) -> None: ...
|
||||
def connection_lost(self, exc: Exception) -> None: ...
|
||||
def connection_lost(self, exc: Optional[Exception]) -> None: ...
|
||||
def pause_writing(self) -> None: ...
|
||||
def resume_writing(self) -> None: ...
|
||||
|
||||
class Protocol(BaseProtocol):
|
||||
def data_received(self, data: bytes) -> None: ...
|
||||
def eof_received(self) -> bool: ...
|
||||
def eof_received(self) -> Optional[bool]: ...
|
||||
|
||||
class DatagramProtocol(BaseProtocol):
|
||||
def datagram_received(self, data: Union[bytes, Text], addr: Tuple[str, int]) -> None: ...
|
||||
@@ -20,5 +20,5 @@ class DatagramProtocol(BaseProtocol):
|
||||
|
||||
class SubprocessProtocol(BaseProtocol):
|
||||
def pipe_data_received(self, fd: int, data: Union[bytes, Text]) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Exception) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Optional[Exception]) -> None: ...
|
||||
def process_exited(self) -> None: ...
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
from typing import Awaitable, TypeVar
|
||||
|
||||
_T = TypeVar('_T')
|
||||
|
||||
def run(main: Awaitable[_T], *, debug: bool = ...) -> _T: ...
|
||||
@@ -68,7 +68,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
|
||||
client_connected_cb: _ClientConnectedCallback = ...,
|
||||
loop: Optional[events.AbstractEventLoop] = ...) -> None: ...
|
||||
def connection_made(self, transport: transports.BaseTransport) -> None: ...
|
||||
def connection_lost(self, exc: Exception) -> None: ...
|
||||
def connection_lost(self, exc: Optional[Exception]) -> None: ...
|
||||
def data_received(self, data: bytes) -> None: ...
|
||||
def eof_received(self) -> bool: ...
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class SubprocessStreamProtocol(streams.FlowControlMixin,
|
||||
def __init__(self, limit: int, loop: events.AbstractEventLoop) -> None: ...
|
||||
def connection_made(self, transport: transports.BaseTransport) -> None: ...
|
||||
def pipe_data_received(self, fd: int, data: Union[bytes, Text]) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Exception) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Optional[Exception]) -> None: ...
|
||||
def process_exited(self) -> None: ...
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import concurrent.futures
|
||||
import sys
|
||||
from typing import (Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable,
|
||||
Coroutine, Generator, Iterable, Awaitable, overload, Sequence, Iterator,
|
||||
Optional)
|
||||
from types import FrameType
|
||||
import concurrent.futures
|
||||
from .events import AbstractEventLoop
|
||||
from .futures import Future
|
||||
|
||||
@@ -70,3 +71,8 @@ class Task(Future[_T], Generic[_T]):
|
||||
def cancel(self) -> bool: ...
|
||||
def _step(self, value: Any = ..., exc: Exception = ...) -> None: ...
|
||||
def _wakeup(self, future: Future[Any]) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 7):
|
||||
def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ...
|
||||
def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task: ...
|
||||
def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task]: ...
|
||||
|
||||
@@ -495,6 +495,8 @@ class memoryview(Sized, Container[int]):
|
||||
ndim = ... # type: int
|
||||
|
||||
def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ...
|
||||
def __enter__(self) -> memoryview: ...
|
||||
def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> bool: ...
|
||||
|
||||
@overload
|
||||
def __getitem__(self, i: int) -> int: ...
|
||||
@@ -557,7 +559,6 @@ class slice:
|
||||
|
||||
class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ...
|
||||
def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __contains__(self, x: object) -> bool: ...
|
||||
@overload
|
||||
@@ -942,7 +943,7 @@ class BaseException:
|
||||
__cause__ = ... # type: Optional[BaseException]
|
||||
__context__ = ... # type: Optional[BaseException]
|
||||
__traceback__ = ... # type: Optional[TracebackType]
|
||||
def __init__(self, *args: object, **kwargs: object) -> None: ...
|
||||
def __init__(self, *args: object) -> None: ...
|
||||
def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ...
|
||||
|
||||
class GeneratorExit(BaseException): ...
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
# Stubs for collections
|
||||
|
||||
# Based on http://docs.python.org/3.2/library/collections.html
|
||||
|
||||
# These are not exported.
|
||||
import sys
|
||||
import typing
|
||||
@@ -54,7 +50,7 @@ _VT = TypeVar('_VT')
|
||||
# namedtuple is special-cased in the type checker; the initializer is ignored.
|
||||
if sys.version_info >= (3, 7):
|
||||
def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *,
|
||||
rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ...
|
||||
rename: bool = ..., module: Optional[str] = ..., defaults: Optional[Iterable[Any]] = ...) -> Type[tuple]: ...
|
||||
elif sys.version_info >= (3, 6):
|
||||
def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *,
|
||||
verbose: bool = ..., rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ...
|
||||
@@ -90,7 +86,7 @@ class UserList(MutableSequence[_T]):
|
||||
@overload
|
||||
def __getitem__(self, i: int) -> _T: ...
|
||||
@overload
|
||||
def __getitem__(self, i: slice) -> Sequence[_T]: ...
|
||||
def __getitem__(self, i: slice) -> MutableSequence[_T]: ...
|
||||
@overload
|
||||
def __setitem__(self, i: int, o: _T) -> None: ...
|
||||
@overload
|
||||
@@ -221,7 +217,7 @@ class deque(MutableSequence[_T], Generic[_T]):
|
||||
@overload
|
||||
def __getitem__(self, index: int) -> _T: ...
|
||||
@overload
|
||||
def __getitem__(self, s: slice) -> Sequence[_T]:
|
||||
def __getitem__(self, s: slice) -> MutableSequence[_T]:
|
||||
raise TypeError
|
||||
@overload
|
||||
def __setitem__(self, i: int, x: _T) -> None: ...
|
||||
@@ -305,7 +301,7 @@ class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
|
||||
_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict)
|
||||
|
||||
class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
|
||||
default_factory = ... # type: Callable[[], _VT]
|
||||
default_factory = ... # type: Optional[Callable[[], _VT]]
|
||||
|
||||
@overload
|
||||
def __init__(self, **kwargs: _VT) -> None: ...
|
||||
|
||||
@@ -20,7 +20,12 @@ _Namespace = Namespace
|
||||
class BaseManager(ContextManager[BaseManager]):
|
||||
address: Union[str, Tuple[str, int]]
|
||||
def connect(self) -> None: ...
|
||||
def register(self, typeid: str, callable: Any = ...) -> None: ...
|
||||
@classmethod
|
||||
def register(cls, typeid: str, callable: Optional[Callable] = ...,
|
||||
proxytype: Any = ...,
|
||||
exposed: Optional[Sequence[str]] = ...,
|
||||
method_to_typeid: Optional[Mapping[str, str]] = ...,
|
||||
create_method: bool = ...) -> None: ...
|
||||
def shutdown(self) -> None: ...
|
||||
def start(self, initializer: Optional[Callable[..., Any]] = ...,
|
||||
initargs: Iterable[Any] = ...) -> None: ...
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# Stubs for pathlib (Python 3.4)
|
||||
|
||||
from typing import Any, Generator, IO, Optional, Sequence, Tuple, Type, TypeVar, Union, List
|
||||
from types import TracebackType
|
||||
import os
|
||||
|
||||
@@ -43,12 +43,9 @@ if sys.version_info >= (3, 5):
|
||||
stderr: Optional[_TXT] = ...) -> None: ...
|
||||
def check_returncode(self) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
# Nearly same args as Popen.__init__ except for timeout, input, and check
|
||||
if sys.version_info >= (3, 7):
|
||||
# Nearly the same args as for 3.6, except for capture_output and text
|
||||
def run(args: _CMD,
|
||||
timeout: Optional[float] = ...,
|
||||
input: Optional[_TXT] = ...,
|
||||
check: bool = ...,
|
||||
bufsize: int = ...,
|
||||
executable: _PATH = ...,
|
||||
stdin: _FILE = ...,
|
||||
@@ -66,8 +63,38 @@ if sys.version_info >= (3, 5):
|
||||
start_new_session: bool = ...,
|
||||
pass_fds: Any = ...,
|
||||
*,
|
||||
capture_output: bool = ...,
|
||||
check: bool = ...,
|
||||
encoding: Optional[str] = ...,
|
||||
errors: Optional[str] = ...) -> CompletedProcess: ...
|
||||
errors: Optional[str] = ...,
|
||||
input: Optional[_TXT] = ...,
|
||||
text: Optional[bool] = ...,
|
||||
timeout: Optional[float] = ...) -> CompletedProcess: ...
|
||||
elif sys.version_info >= (3, 6):
|
||||
# Nearly same args as Popen.__init__ except for timeout, input, and check
|
||||
def run(args: _CMD,
|
||||
bufsize: int = ...,
|
||||
executable: _PATH = ...,
|
||||
stdin: _FILE = ...,
|
||||
stdout: _FILE = ...,
|
||||
stderr: _FILE = ...,
|
||||
preexec_fn: Callable[[], Any] = ...,
|
||||
close_fds: bool = ...,
|
||||
shell: bool = ...,
|
||||
cwd: Optional[_PATH] = ...,
|
||||
env: Optional[_ENV] = ...,
|
||||
universal_newlines: bool = ...,
|
||||
startupinfo: Any = ...,
|
||||
creationflags: int = ...,
|
||||
restore_signals: bool = ...,
|
||||
start_new_session: bool = ...,
|
||||
pass_fds: Any = ...,
|
||||
*,
|
||||
check: bool = ...,
|
||||
encoding: Optional[str] = ...,
|
||||
errors: Optional[str] = ...,
|
||||
input: Optional[_TXT] = ...,
|
||||
timeout: Optional[float] = ...) -> CompletedProcess: ...
|
||||
else:
|
||||
# Nearly same args as Popen.__init__ except for timeout, input, and check
|
||||
def run(args: _CMD,
|
||||
@@ -182,6 +209,7 @@ STDOUT = ... # type: int
|
||||
DEVNULL = ... # type: int
|
||||
class SubprocessError(Exception): ...
|
||||
class TimeoutExpired(SubprocessError):
|
||||
def __init__(self, cmd: _CMD, timeout: float, output: Optional[_TXT] = ..., stderr: Optional[_TXT] = ...) -> None: ...
|
||||
# morally: _CMD
|
||||
cmd = ... # type: Any
|
||||
timeout = ... # type: float
|
||||
|
||||
@@ -254,6 +254,12 @@ class MutableSequence(Sequence[_T], Generic[_T]):
|
||||
def insert(self, index: int, object: _T) -> None: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __getitem__(self, i: int) -> _T: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __getitem__(self, s: slice) -> MutableSequence[_T]: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
def __setitem__(self, i: int, o: _T) -> None: ...
|
||||
@overload
|
||||
@abstractmethod
|
||||
@@ -535,13 +541,17 @@ class Pattern(Generic[AnyStr]):
|
||||
def get_type_hints(obj: Callable, globalns: Optional[dict[str, Any]] = ...,
|
||||
localns: Optional[dict[str, Any]] = ...) -> dict[str, Any]: ...
|
||||
|
||||
@overload
|
||||
def cast(tp: Type[_T], obj: Any) -> _T: ...
|
||||
@overload
|
||||
def cast(tp: str, obj: Any) -> Any: ...
|
||||
|
||||
# Type constructors
|
||||
|
||||
# NamedTuple is special-cased in the type checker
|
||||
class NamedTuple(tuple):
|
||||
_field_types = ... # type: collections.OrderedDict[str, Type[Any]]
|
||||
_field_defaults: Dict[str, Any] = ...
|
||||
_fields = ... # type: Tuple[str, ...]
|
||||
_source = ... # type: str
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ consistent_files = [
|
||||
{'stdlib/3/concurrent/futures/_base.pyi', 'third_party/2/concurrent/futures/_base.pyi'},
|
||||
{'stdlib/3/concurrent/futures/thread.pyi', 'third_party/2/concurrent/futures/thread.pyi'},
|
||||
{'stdlib/3/concurrent/futures/process.pyi', 'third_party/2/concurrent/futures/process.pyi'},
|
||||
{'stdlib/3.7/dataclasses.pyi', 'third_party/3/dataclasses.pyi'},
|
||||
{'stdlib/3/pathlib.pyi', 'third_party/2/pathlib2.pyi'},
|
||||
{'stdlib/3.7/contextvars.pyi', 'third_party/3.5/contextvars.pyi'},
|
||||
]
|
||||
|
||||
def main():
|
||||
|
||||
@@ -16,8 +16,8 @@ if __name__ == '__main__':
|
||||
str(dirpath / 'mypy')], check=True)
|
||||
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r',
|
||||
str(dirpath / 'mypy/test-requirements.txt')], check=True)
|
||||
shutil.copytree('stdlib', str(dirpath / 'mypy/typeshed/stdlib'))
|
||||
shutil.copytree('third_party', str(dirpath / 'mypy/typeshed/third_party'))
|
||||
shutil.copytree('stdlib', str(dirpath / 'mypy/mypy/typeshed/stdlib'))
|
||||
shutil.copytree('third_party', str(dirpath / 'mypy/mypy/typeshed/third_party'))
|
||||
try:
|
||||
subprocess.run(['pytest', '-n12'], cwd=str(dirpath / 'mypy'), check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
r"""Test runner for typeshed.
|
||||
|
||||
Depends on mypy and pytype being installed.
|
||||
Depends on pytype being installed.
|
||||
|
||||
If pytype is installed:
|
||||
1. For every pyi, do nothing if it is in pytype_blacklist.txt.
|
||||
@@ -9,7 +9,7 @@ If pytype is installed:
|
||||
"pytd <foo.pyi>" in a separate process.
|
||||
3. If the file is not in the blacklist run
|
||||
"pytype --typeshed-location=typeshed_location --module-name=foo \
|
||||
--convert-to-pickle=tmp_file <foo.pyi>.
|
||||
--parse-pyi <foo.pyi>.
|
||||
Option two will parse the file, mostly syntactical correctness. Option three
|
||||
will load the file and all the builtins, typeshed dependencies. This will
|
||||
also discover incorrect usage of imported modules.
|
||||
@@ -37,9 +37,10 @@ parser.add_argument('--pytype-bin-dir', type=str, default='',
|
||||
# Set to true to print a stack trace every time an exception is thrown.
|
||||
parser.add_argument('--print-stderr', type=bool, default=False,
|
||||
help='Print stderr every time an error is encountered.')
|
||||
# We need to invoke python3.6. The default here works with our travis tests.
|
||||
parser.add_argument('--python36-exe', type=str,
|
||||
default='/opt/python/3.6/bin/python3.6',
|
||||
# We need to invoke python2.7 and 3.6.
|
||||
parser.add_argument('--python27-exe', type=str, default='python2.7',
|
||||
help='Path to a python 2.7 interpreter.')
|
||||
parser.add_argument('--python36-exe', type=str, default='python3.6',
|
||||
help='Path to a python 3.6 interpreter.')
|
||||
|
||||
Dirs = collections.namedtuple('Dirs', ['pytype', 'typeshed'])
|
||||
@@ -165,7 +166,7 @@ def pytype_test(args):
|
||||
for p in paths:
|
||||
if not os.path.isdir(p):
|
||||
print('Cannot find typeshed subdir at %s '
|
||||
'(specify parent dir via --typeshed_location)' % p)
|
||||
'(specify parent dir via --typeshed-location)' % p)
|
||||
return 0, 0
|
||||
|
||||
if can_run(dirs.pytype, 'pytd', '-h'):
|
||||
@@ -176,16 +177,25 @@ def pytype_test(args):
|
||||
print('Cannot run pytd. Did you install pytype?')
|
||||
return 0, 0
|
||||
|
||||
if not can_run('', args.python36_exe, '--version'):
|
||||
print('Cannot run python3.6 from %s. (point to a valid executable via '
|
||||
'--python36-exe)' % args.python36_exe)
|
||||
return 0, 0
|
||||
for python_version_str in ('27', '36'):
|
||||
dest = 'python%s_exe' % python_version_str
|
||||
version = '.'.join(list(python_version_str))
|
||||
arg = '--python%s-exe' % python_version_str
|
||||
if not can_run('', getattr(args, dest), '--version'):
|
||||
print('Cannot run Python {version}. (point to a valid executable '
|
||||
'via {arg})'.format(version=version, arg=arg))
|
||||
return 0, 0
|
||||
|
||||
stdlib = 'stdlib/'
|
||||
six = 'third_party/.*/six/'
|
||||
mypy_extensions = 'third_party/.*/mypy_extensions'
|
||||
wanted = re.compile(
|
||||
r'(?:%s).*\.pyi$' % '|'.join([stdlib, six, mypy_extensions]))
|
||||
# TODO(rchen152): Keep expanding our third_party/ coverage so we can move
|
||||
# to a small blacklist rather than an ever-growing whitelist.
|
||||
wanted = [
|
||||
'stdlib/',
|
||||
'third_party/.*/mypy_extensions',
|
||||
'third_party/.*/pkg_resources',
|
||||
'third_party/.*/six/',
|
||||
'third_party/.*/yaml/',
|
||||
]
|
||||
wanted_re = re.compile(r'(?:%s).*\.pyi$' % '|'.join(wanted))
|
||||
skip, parse_only = load_blacklist(dirs)
|
||||
skipped = PathMatcher(skip)
|
||||
parse_only = PathMatcher(parse_only)
|
||||
@@ -195,16 +205,19 @@ def pytype_test(args):
|
||||
bad = []
|
||||
|
||||
def _make_test(filename, major_version):
|
||||
if major_version == 3:
|
||||
version = '3.6'
|
||||
exe = args.python36_exe
|
||||
else:
|
||||
version = '2.7'
|
||||
exe = args.python27_exe
|
||||
run_cmd = [
|
||||
pytype_exe,
|
||||
'--module-name=%s' % _get_module_name(filename),
|
||||
'--parse-pyi',
|
||||
'-V %s' % version,
|
||||
'--python_exe=%s' % exe,
|
||||
]
|
||||
if major_version == 3:
|
||||
run_cmd += [
|
||||
'-V 3.6',
|
||||
'--python_exe=%s' % args.python36_exe,
|
||||
]
|
||||
return BinaryRun(run_cmd + [filename],
|
||||
dry_run=args.dry_run,
|
||||
env={"TYPESHED_HOME": dirs.typeshed})
|
||||
@@ -214,7 +227,7 @@ def pytype_test(args):
|
||||
for f in sorted(filenames):
|
||||
f = os.path.join(root, f)
|
||||
rel = _get_relative(f)
|
||||
if wanted.search(rel):
|
||||
if wanted_re.search(rel):
|
||||
if parse_only.search(rel):
|
||||
pytd_run.append(f)
|
||||
elif not skipped.search(rel):
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .urllib.request import *
|
||||
@@ -0,0 +1 @@
|
||||
from .urllib.response import *
|
||||
@@ -0,0 +1 @@
|
||||
from .urllib.request import *
|
||||
@@ -0,0 +1 @@
|
||||
from .urllib.response import *
|
||||
@@ -137,7 +137,7 @@ public class PyStdlibTypeProvider extends PyTypeProviderBase {
|
||||
if (OPEN_FUNCTIONS.contains(qname) && callSite instanceof PyCallExpression) {
|
||||
return getOpenFunctionCallType(function, (PyCallExpression)callSite, LanguageLevel.forElement(callSite), context);
|
||||
}
|
||||
else if ("tuple.__init__".equals(qname) && callSite instanceof PyCallExpression) {
|
||||
else if ("tuple.__new__".equals(qname) && callSite instanceof PyCallExpression) {
|
||||
return getTupleInitializationType((PyCallExpression)callSite, context);
|
||||
}
|
||||
else if ("tuple.__add__".equals(qname) && callSite instanceof PyBinaryExpression) {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
public void testExistingImportsAlwaysSuggestedFirstEvenIfNonProject() {
|
||||
doMultiFileAutoImportTest("Import", quickfix -> {
|
||||
final List<String> candidates = ContainerUtil.map(quickfix.getCandidates(), c -> c.getPresentableText("datetime"));
|
||||
assertOrderedEquals(candidates, "datetime from datetime", "mod.datetime");
|
||||
assertOrderedEquals(candidates, "datetime(date) from datetime", "mod.datetime");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user