Skip to content

Commit

Permalink
Merge pull request python#4 from cocoatomo/update-master
Browse files Browse the repository at this point in the history
Have master branch up-to-date
  • Loading branch information
tk0miya authored Jul 17, 2018
2 parents 28bed78 + 9cc4b00 commit 27530aa
Show file tree
Hide file tree
Showing 505 changed files with 17,303 additions and 8,007 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
# 967 E701 multiple statements on one line (colon)
# 457 F811 redefinition
# 390 E305 expected 2 blank lines
# 4 E741 ambiguous variable name

# Nice-to-haves ignored for now
# 159 E128 continuation line under-indented for visual indent
# 34 E127 continuation line over-indented for visual indent

[flake8]
ignore = F401, F403, F405, F811, E127, E128, E301, E302, E305, E501, E701, E704, B303
ignore = F401, F403, F405, F811, E127, E128, E301, E302, E305, E501, E701, E704, E741, B303
# We are checking with Python 3 but many of the stubs are Python 2 stubs.
# A nice future improvement would be to provide separate .flake8
# configurations for Python 2 and Python 3 files.
Expand Down
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ matrix:
- python: "3.6"
env: TEST_CMD="./tests/mypy_selftest.py"
- python: "3.5"
env: TEST_CMD="./tests/mypy_test.py --no-implicit-optional"
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
- if [[ $TRAVIS_PYTHON_VERSION == '3.6-dev' ]]; then pip install -U flake8==3.3.0 flake8-bugbear>=17.3.0 flake8-pyi>=17.1.0; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6-dev' ]]; 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 -U git+git://github.com/google/pytype; 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
- 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
24 changes: 19 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ At present the core developers are (alphabetically):
* David Fisher (@ddfisher)
* Łukasz Langa (@ambv)
* Jukka Lehtosalo (@JukkaL)
* Ivan Levkivskyi (@ilevkivskyi)
* Matthias Kramm (@matthiaskramm)
* Greg Price (@gnprice)
* Guido van Rossum (@gvanrossum)
Expand Down Expand Up @@ -133,6 +134,15 @@ included in ``__all__`` (if present), and whose names do not start with an
underscore are more likely to merit inclusion in a stub. If in doubt, err
on the side of including more objects.

**NEW:** Sometimes it makes sense to include non-public objects
in a stub. Mark these with a comment of the form ``# undocumented``.
See the [motivation](https://github.com/python/typeshed/issues/1902).
Example:

```python
def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented
```

### Using stubgen

Mypy includes a tool called [stubgen](https://github.com/python/mypy/blob/master/mypy/stubgen.py)
Expand Down Expand Up @@ -175,8 +185,7 @@ you should know about.

Style conventions for stub files are different from PEP 8. The general
rule is that they should be as concise as possible. Specifically:
* there is no line length limit;
* prefer long lines over elaborate indentation;
* lines can be up to 130 characters long;
* all function bodies should be empty;
* prefer ``...`` over ``pass``;
* prefer ``...`` on the same line as the class/function signature;
Expand All @@ -202,7 +211,9 @@ Some further tips for good type hints:
positions, in favor of covariant types like `Mapping` or `Sequence`;
* avoid Union return types: https://github.com/python/mypy/issues/1693;
* in Python 2, whenever possible, use `unicode` if that's the only
possible type, and `Text` if it can be either `unicode` or `bytes`.
possible type, and `Text` if it can be either `unicode` or `bytes`;
* use platform checks like `if sys.platform == 'win32'` to denote
platform-dependent APIs.

Imports in stubs are considered private (not part of the exported API)
unless:
Expand Down Expand Up @@ -303,8 +314,6 @@ missing, incomplete or incorrect) and we won't add noise to the
tracker by labeling all of them. Here's what our labels mean. (We
also apply these to pull requests.)

* **blocked**: This issue is waiting for the resolution of some issue
external to typeshed.
* **bug**: It's a bug in a stub.
* **bytes-unicode**: It's related to bytes vs. unicode, usually Python 2.
* **feature**: It's a new typeshed feature.
Expand All @@ -316,6 +325,11 @@ also apply these to pull requests.)
* **size-medium**: An issue of average complexity.
* **size-small**: An issue that will take only little effort to fix.

Sometimes a PR can't make progress until some external issue is
addressed. We indicate this by editing the subject to add a ``[WIP]``
prefix. (This should be removed before committing the issue once
unblocked!)

### Core developer guidelines

Core developers should follow these rules when processing pull requests:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For information on how to use `typeshed`, read below. Information for
contributors can be found in [CONTRIBUTING.md](CONTRIBUTING.md). **Please read
it before submitting pull requests.**

Typeshed supports Python versions 2.7 and 3.3 and up.
Typeshed supports Python versions 2.7 and 3.4 and up.

## Using

Expand Down
2 changes: 1 addition & 1 deletion requirements-tests-py2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-e git+https://github.com/google/pytype.git@master#egg=pytype
pytype>=2018.6.19
6 changes: 3 additions & 3 deletions requirements-tests-py3.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
git+https://github.com/python/mypy.git@master
typed-ast>=1.0.4
flake8==3.3.0
flake8-bugbear>=17.3.0
flake8-pyi>=17.1.0
flake8==3.5.0
flake8-bugbear==18.2.0
flake8-pyi>=18.3.1
1 change: 0 additions & 1 deletion stdlib/2/ConfigParser.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, IO, Sequence, Tuple, Union, List, Dict

__all__ = ... # type: List[str]
DEFAULTSECT = ... # type: str
MAX_INTERPOLATION_DEPTH = ... # type: int

Expand Down
1 change: 0 additions & 1 deletion stdlib/2/SocketServer.pyi

This file was deleted.

99 changes: 99 additions & 0 deletions stdlib/2/SocketServer.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# NB: SocketServer.pyi and socketserver.pyi must remain consistent!
# Stubs for socketserver

from typing import Any, BinaryIO, Optional, Tuple, Type
from socket import SocketType
import sys
import types

class BaseServer:
address_family = ... # type: int
RequestHandlerClass = ... # type: type
server_address = ... # type: Tuple[str, int]
socket = ... # type: SocketType
allow_reuse_address = ... # type: bool
request_queue_size = ... # type: int
socket_type = ... # type: int
timeout = ... # type: Optional[float]
def __init__(self, server_address: Tuple[str, int],
RequestHandlerClass: type) -> None: ...
def fileno(self) -> int: ...
def handle_request(self) -> None: ...
def serve_forever(self, poll_interval: float = ...) -> None: ...
def shutdown(self) -> None: ...
def server_close(self) -> None: ...
def finish_request(self, request: bytes,
client_address: Tuple[str, int]) -> None: ...
def get_request(self) -> None: ...
def handle_error(self, request: bytes,
client_address: Tuple[str, int]) -> None: ...
def handle_timeout(self) -> None: ...
def process_request(self, request: bytes,
client_address: Tuple[str, int]) -> None: ...
def server_activate(self) -> None: ...
def server_bind(self) -> None: ...
def verify_request(self, request: bytes,
client_address: Tuple[str, int]) -> bool: ...
if sys.version_info >= (3, 6):
def __enter__(self) -> BaseServer: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType]) -> bool: ...
if sys.version_info >= (3, 3):
def service_actions(self) -> None: ...

class TCPServer(BaseServer):
def __init__(self, server_address: Tuple[str, int],
RequestHandlerClass: type,
bind_and_activate: bool = ...) -> None: ...

class UDPServer(BaseServer):
def __init__(self, server_address: Tuple[str, int],
RequestHandlerClass: type,
bind_and_activate: bool = ...) -> None: ...

if sys.platform != 'win32':
class UnixStreamServer(BaseServer):
def __init__(self, server_address: Tuple[str, int],
RequestHandlerClass: type,
bind_and_activate: bool = ...) -> None: ...

class UnixDatagramServer(BaseServer):
def __init__(self, server_address: Tuple[str, int],
RequestHandlerClass: type,
bind_and_activate: bool = ...) -> None: ...

class ForkingMixIn: ...
class ThreadingMixIn: ...

class ForkingTCPServer(ForkingMixIn, TCPServer): ...
class ForkingUDPServer(ForkingMixIn, UDPServer): ...
class ThreadingTCPServer(ThreadingMixIn, TCPServer): ...
class ThreadingUDPServer(ThreadingMixIn, UDPServer): ...
if sys.platform != 'win32':
class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer): ...
class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): ...


class BaseRequestHandler:
# Those are technically of types, respectively:
# * Union[SocketType, Tuple[bytes, SocketType]]
# * Union[Tuple[str, int], str]
# But there are some concerns that having unions here would cause
# too much inconvenience to people using it (see
# https://github.com/python/typeshed/pull/384#issuecomment-234649696)
request = ... # type: Any
client_address = ... # type: Any

server = ... # type: BaseServer
def setup(self) -> None: ...
def handle(self) -> None: ...
def finish(self) -> None: ...

class StreamRequestHandler(BaseRequestHandler):
rfile = ... # type: BinaryIO
wfile = ... # type: BinaryIO

class DatagramRequestHandler(BaseRequestHandler):
rfile = ... # type: BinaryIO
wfile = ... # type: BinaryIO
2 changes: 2 additions & 0 deletions stdlib/2/UserDict.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class IterableUserDict(UserDict[_KT, _VT], Generic[_KT, _VT]):

class DictMixin(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT]):
def has_key(self, key: _KT) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_KT]: ...

# From typing.Mapping[_KT, _VT]
# (can't inherit because of keys())
Expand Down
19 changes: 17 additions & 2 deletions stdlib/2/UserList.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import collections
from typing import Iterable, MutableSequence, TypeVar, Union, overload

class UserList(collections.MutableSequence): ...
_T = TypeVar("_T")
_ULT = TypeVar("_ULT", bound=UserList)

class UserList(MutableSequence[_T]):
def insert(self, index: int, object: _T) -> None: ...
@overload
def __setitem__(self, i: int, o: _T) -> None: ...
@overload
def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...
def __delitem__(self, i: Union[int, slice]) -> None: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> _T: ...
@overload
def __getitem__(self: _ULT, s: slice) -> _ULT: ...
def sort(self) -> None: ...
70 changes: 68 additions & 2 deletions stdlib/2/UserString.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
import collections
from typing import Any, Iterable, List, MutableSequence, Sequence, Optional, overload, Text, TypeVar, Tuple, Union

class UserString(collections.Sequence): ...
class MutableString(UserString, collections.MutableSequence): ...
_UST = TypeVar("_UST", bound=UserString)
_MST = TypeVar("_MST", bound=MutableString)

class UserString(Sequence[UserString]):
def __init__(self, seq: object) -> None: ...
def __int__(self) -> int: ...
def __long__(self) -> long: ...
def __float__(self) -> float: ...
def __complex__(self) -> complex: ...
def __hash__(self) -> int: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self: _UST, i: int) -> _UST: ...
@overload
def __getitem__(self: _UST, s: slice) -> _UST: ...
def __add__(self: _UST, other: Any) -> _UST: ...
def __radd__(self: _UST, other: Any) -> _UST: ...
def __mul__(self: _UST, other: int) -> _UST: ...
def __rmul__(self: _UST, other: int) -> _UST: ...
def __mod__(self: _UST, args: Any) -> _UST: ...
def capitalize(self: _UST) -> _UST: ...
def center(self: _UST, width: int, *args: Any) -> _UST: ...
def count(self, sub: int, start: int = ..., end: int = ...) -> int: ...
def decode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ...
def encode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ...
def endswith(self, suffix: Text, start: int = ..., end: int = ...) -> bool: ...
def expandtabs(self: _UST, tabsize: int = ...) -> _UST: ...
def find(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def index(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def isalpha(self) -> bool: ...
def isalnum(self) -> bool: ...
def isdecimal(self) -> bool: ...
def isdigit(self) -> bool: ...
def islower(self) -> bool: ...
def isnumeric(self) -> bool: ...
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
def join(self, seq: Iterable[Text]) -> Text: ...
def ljust(self: _UST, width: int, *args: Any) -> _UST: ...
def lower(self: _UST) -> _UST: ...
def lstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def partition(self, sep: Text) -> Tuple[Text, Text, Text]: ...
def replace(self: _UST, old: Text, new: Text, maxsplit: int = ...) -> _UST: ...
def rfind(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def rindex(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def rjust(self: _UST, width: int, *args: Any) -> _UST: ...
def rpartition(self, sep: Text) -> Tuple[Text, Text, Text]: ...
def rstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def split(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ...
def rsplit(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ...
def splitlines(self, keepends: int = ...) -> List[Text]: ...
def startswith(self, suffix: Text, start: int = ..., end: int = ...) -> bool: ...
def strip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def swapcase(self: _UST) -> _UST: ...
def title(self: _UST) -> _UST: ...
def translate(self: _UST, *args: Any) -> _UST: ...
def upper(self: _UST) -> _UST: ...
def zfill(self: _UST, width: int) -> _UST: ...

class MutableString(UserString, MutableSequence[MutableString]):
def __setitem__(self, index: Union[int, slice], sub: Any) -> None: ...
def __delitem__(self, index: Union[int, slice]) -> None: ...
def immutable(self) -> UserString: ...
def __iadd__(self: _MST, other: Any) -> _MST: ...
def __imul__(self, n: int) -> _MST: ...
def insert(self, index: int, value: Any) -> None: ...
Loading

0 comments on commit 27530aa

Please sign in to comment.