Skip to content

Commit 89c09ef

Browse files
committed
Merge branch 'python/master'
* python/master: (269 commits) allow Optional[float] for asyncio.wait() timeout arg (python#1860) Clean up the pytype blacklist. (python#1851) filter function: make the callable of the first overload non-optional so that mypy is able to select the second overload for the case. (python#1855) Accept Text in distutils *Version classes (python#1854) Add attrs library (python#1838) Add type stub for the lzma module (python#1844) Add ImportError attributes name, path for Python 3.3+ (python#1849) Add 'message' to click.decorators.version_option (python#1845) PEP 553 and PEP 564 (python#1846) Adding py36 additions to datetime module (python#1848) Remove incomplete thrift stubs that cause false positives. (python#1827) adding curses.ascii, curses.panel and curses.textpad modules (python#1792) Fix requests session hooks type (python#1794) Add StringIO.name and BytesIO.name (python#1802) Fix werkzeug environ type (python#1831) Change the return type of unittest.TestCase.fail() to NoReturn (python#1843) _curses.tparm works on bytes, not str (python#1828) Refine types for distutils.version (python#1835) Add stub for stat.filemode (python#1837) modify pytype_test to run from within pytype too, and support python3 (python#1817) ...
2 parents 9d616a2 + 1713ad6 commit 89c09ef

File tree

258 files changed

+6224
-3654
lines changed

Some content is hidden

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

258 files changed

+6224
-3654
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# 34 E127 continuation line over-indented for visual indent
1515

1616
[flake8]
17-
ignore = F401, F811, E127, E128, E301, E302, E305, E501, E701, E704, B303
17+
ignore = F401, F403, F405, F811, E127, E128, E301, E302, E305, E501, E701, E704, B303
1818
# We are checking with Python 3 but many of the stubs are Python 2 stubs.
1919
# A nice future improvement would be to provide separate .flake8
2020
# configurations for Python 2 and Python 3 files.

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ matrix:
1111
env: TEST_CMD="./tests/mypy_test.py --no-implicit-optional"
1212
- python: "2.7"
1313
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"
14+
sudo: true
1415

1516
install:
1617
# pytype needs py-2.7, mypy needs py-3.3+. Additional logic in runtests.py
1718
- 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
1819
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/python/typed_ast; fi
19-
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -U git+git://github.com/google/pytype; fi
20+
- 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
2021

2122
script:
2223
- $TEST_CMD

CONTRIBUTING.md

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ For every pull request, we aim to promptly either merge it or say why
6969
it's not yet ready; if you go a few days without a reply, please feel
7070
free to ping the thread by adding a new comment.
7171

72+
To get your pull request merged sooner, you should explain why you are
73+
making the change. For example, you can point to a code sample that is
74+
processed incorrectly by a type checker. It is also helpful to add
75+
links to online documentation or to the implementation of the code
76+
you are changing.
77+
78+
Also, do not squash your commits after you have submitted a pull request, as this
79+
erases context during review. We will squash commits when the pull request is merged.
80+
7281
At present the core developers are (alphabetically):
7382
* David Fisher (@ddfisher)
7483
* Łukasz Langa (@ambv)
@@ -106,19 +115,59 @@ message where you received permission**.
106115
Make sure your changes pass the tests (the [README](README.md#running-the-tests)
107116
has more information).
108117

118+
### What to include
119+
120+
Stubs should include all public objects (classes, functions, constants,
121+
etc.) in the module they cover. Omitting objects can confuse users,
122+
because users who see an error like "module X has no attribute Y" will
123+
not know whether the error appeared because their code had a bug or
124+
because the stub is wrong. If you are submitting stubs to typeshed and
125+
you are unable to provide fully typed stubs for some of the objects in
126+
the library, you can use stubgen (see below) to generate untyped stubs.
127+
Although we prefer having exact types for all stubs, such stubs are
128+
better than nothing.
129+
130+
What counts as a "public object" is not always clear. Use your judgment,
131+
but objects that are listed in the module's documentation, that are
132+
included in ``__all__`` (if present), and whose names do not start with an
133+
underscore are more likely to merit inclusion in a stub. If in doubt, err
134+
on the side of including more objects.
135+
109136
### Using stubgen
110137

111138
Mypy includes a tool called [stubgen](https://github.com/python/mypy/blob/master/mypy/stubgen.py)
112139
that you can use as a starting point for your stubs. Note that this
113140
generator is currently unable to determine most argument and return
114141
types and omits them or uses ``Any`` in their place. Fill out the types
115-
that you know. Leave out modules that you are not using at all. It's
116-
strictly better to provide partial stubs that have detailed type
117-
information than to submit unmodified ``stubgen`` output for an entire
118-
library.
142+
that you know.
119143

120144
### Stub file coding style
121145

146+
#### Syntax example
147+
148+
The below is an excerpt from the types for the `datetime` module.
149+
150+
```python
151+
MAXYEAR: int
152+
MINYEAR: int
153+
154+
class date:
155+
def __init__(self, year: int, month: int, day: int) -> None: ...
156+
@classmethod
157+
def fromtimestamp(cls, timestamp: float) -> date: ...
158+
@classmethod
159+
def today(cls) -> date: ...
160+
@classmethod
161+
def fromordinal(cls, ordinal: int) -> date: ...
162+
@property
163+
def year(self) -> int: ...
164+
def replace(self, year: int = ..., month: int = ..., day: int = ...) -> date: ...
165+
def ctime(self) -> str: ...
166+
def weekday(self) -> int: ...
167+
```
168+
169+
#### Conventions
170+
122171
Stub files are *like* Python files and you should generally expect them
123172
to look the same. Your tools should be able to successfully treat them
124173
as regular Python files. However, there are a few important differences
@@ -136,8 +185,25 @@ rule is that they should be as concise as possible. Specifically:
136185
* use a single blank line between top-level class definitions, or none
137186
if the classes are very small;
138187
* do not use docstrings;
188+
* use variable annotations instead of type comments, even for stubs
189+
that target older versions of Python;
139190
* for arguments with a type and a default, use spaces around the `=`.
140191

192+
Stub files should only contain information necessary for the type
193+
checker, and leave out unnecessary detail:
194+
* for arguments with a default, use `...` instead of the actual
195+
default;
196+
* for arguments that default to `None`, use `Optional[]` explicitly
197+
(see below for details);
198+
* use `float` instead of `Union[int, float]`.
199+
200+
Some further tips for good type hints:
201+
* avoid invariant collection types (`List`, `Dict`) in argument
202+
positions, in favor of covariant types like `Mapping` or `Sequence`;
203+
* avoid Union return types: https://github.com/python/mypy/issues/1693;
204+
* in Python 2, whenever possible, use `unicode` if that's the only
205+
possible type, and `Text` if it can be either `unicode` or `bytes`.
206+
141207
Imports in stubs are considered private (not part of the exported API)
142208
unless:
143209
* they use the form ``from library import name as name`` (sic, using
@@ -231,7 +297,7 @@ project's tracker to fix their documentation.
231297
## Issue-tracker conventions
232298

233299
We aim to reply to all new issues promptly. We'll assign one or more
234-
labels to to indicate we've triaged an issue, but most typeshed issues
300+
labels to indicate we've triaged an issue, but most typeshed issues
235301
are relatively simple (stubs for a given module or package are
236302
missing, incomplete or incorrect) and we won't add noise to the
237303
tracker by labeling all of them. Here's what our labels mean. (We

README.md

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# typeshed
22

3+
[![Build Status](https://travis-ci.org/python/typeshed.svg?branch=master)](https://travis-ci.org/python/typeshed)
34
[![Chat at https://gitter.im/python/typing](https://badges.gitter.im/python/typing.svg)](https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
45

56
## About
@@ -48,30 +49,9 @@ file (i.e., it can be interpreted by Python 3), except all the methods are empty
4849
Python function annotations ([PEP 3107](https://www.python.org/dev/peps/pep-3107/))
4950
are used to describe the types the function has.
5051

51-
See [PEP 484](http://www.python.org/dev/peps/pep-0484/) for the exact syntax
52-
of the stub files.
53-
54-
## Syntax example
55-
56-
The below is an excerpt from the types for the `datetime` module.
57-
58-
```python
59-
from typing import Union
60-
61-
MAXYEAR = ... # type: int
62-
MINYEAR = ... # type: int
63-
64-
class date(object):
65-
def __init__(self, year: int, month: int, day: int) -> None: ...
66-
@classmethod
67-
def fromtimestamp(cls, timestamp: Union[int, float]) -> date: ...
68-
@classmethod
69-
def fromordinal(cls, ordinal: int) -> date: ...
70-
@classmethod
71-
def today(self) -> date: ...
72-
def ctime(self) -> str: ...
73-
def weekday(self) -> int: ...
74-
```
52+
See [PEP 484](http://www.python.org/dev/peps/pep-0484/) for the exact
53+
syntax of the stub files and [CONTRIBUTING.md](CONTRIBUTING.md) for the
54+
coding style used in typeshed.
7555

7656
## Directory structure
7757

@@ -147,7 +127,7 @@ invoking:
147127
(Note that flake8 only works with Python 3.6 or higher.)
148128

149129
To run the pytype tests, you need a separate virtual environment with
150-
Python 2.7. Run:
130+
Python 2.7, and a Python 3.6 interpreter somewhere you can point to. Run:
151131
```
152132
$ virtualenv --python=python2.7 .venv2
153133
$ source .venv2/bin/activate
@@ -156,7 +136,7 @@ $ source .venv2/bin/activate
156136
This will install pytype from its GitHub repo. You can then run pytype
157137
tests by running:
158138
```
159-
(.venv2)$ python tests/pytype_test.py
139+
(.venv2)$ python tests/pytype_test.py --python36-exe=/path/to/python3.6
160140
```
161141

162142
For mypy, if you are in the typeshed repo that is submodule of the

stdlib/2/ConfigParser.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ class RawConfigParser:
7878
def optionxform(self, optionstr: str) -> str: ...
7979
def has_option(self, section: str, option: str) -> bool: ...
8080
def set(self, section: str, option: str, value: Any = ...) -> None: ...
81-
def write(self, fp: file) -> None: ...
81+
def write(self, fp: IO[str]) -> None: ...
8282
def remove_option(self, section: str, option: Any) -> bool: ...
8383
def remove_section(self, section: str) -> bool: ...
84-
def _read(self, fp: file, fpname: str) -> None: ...
84+
def _read(self, fp: IO[str], fpname: str) -> None: ...
8585

8686
class ConfigParser(RawConfigParser):
8787
_KEYCRE = ... # type: Any

0 commit comments

Comments
 (0)