Skip to content

Commit 8c3941f

Browse files
authored
Merge branch 'master' into literal_hash1
2 parents 4e363d3 + 88e8ef2 commit 8c3941f

Some content is hidden

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

85 files changed

+3119
-621
lines changed

appveyor.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
environment:
22
matrix:
33

4-
- PYTHON: "C:\\Python35"
5-
PYTHON_VERSION: "3.5.1"
6-
PYTHON_ARCH: "32"
7-
8-
- PYTHON: "C:\\Python35-x64"
9-
PYTHON_VERSION: "3.5.1"
10-
PYTHON_ARCH: "64"
11-
124
- PYTHON: "C:\\Python36"
135
PYTHON_VERSION: "3.6.x"
146
PYTHON_ARCH: "32"
@@ -50,3 +42,5 @@ skip_commits:
5042
- .travis.yml
5143
- CREDITS
5244
- LICENSE
45+
46+
skip_branch_with_pr: true

docs/source/command_line.rst

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ flag (or its long form ``--help``)::
1414
[--disallow-untyped-calls] [--disallow-untyped-defs]
1515
[--check-untyped-defs] [--disallow-subclassing-any]
1616
[--warn-incomplete-stub] [--warn-redundant-casts]
17-
[--warn-no-return] [--warn-unused-ignores] [--show-error-context]
18-
[-i] [--cache-dir DIR] [--strict-optional]
19-
[--strict-optional-whitelist [GLOB [GLOB ...]]] [--strict]
17+
[--no-warn-no-return] [--warn-return-any] [--warn-unused-ignores]
18+
[--show-error-context] [-i] [--quick-and-dirty] [--cache-dir DIR]
19+
[--strict-optional]
20+
[--strict-optional-whitelist [GLOB [GLOB ...]]]
2021
[--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats]
2122
[--inferstats] [--custom-typing MODULE]
2223
[--custom-typeshed-dir DIR] [--scripts-are-modules]
2324
[--config-file CONFIG_FILE] [--show-column-numbers]
24-
[--find-occurrences CLASS.MEMBER]
25+
[--find-occurrences CLASS.MEMBER] [--strict] [--strict-boolean]
2526
[--cobertura-xml-report DIR] [--html-report DIR]
2627
[--linecount-report DIR] [--linecoverage-report DIR]
2728
[--memory-xml-report DIR] [--old-html-report DIR]
@@ -298,10 +299,31 @@ Here are some more useful flags:
298299
the base class even though that may not actually be the case. This
299300
flag makes mypy raise an error instead.
300301

301-
- ``--incremental`` is an experimental option that enables incremental
302-
type checking. When enabled, mypy caches results from previous runs
302+
.. _incremental:
303+
304+
- ``--incremental`` is an experimental option that enables a module
305+
cache. When enabled, mypy caches results from previous runs
303306
to speed up type checking. Incremental mode can help when most parts
304-
of your program haven't changed since the previous mypy run.
307+
of your program haven't changed since the previous mypy run. A
308+
companion flag is ``--cache-dir DIR``, which specifies where the
309+
cache files are written. By default this is ``.mypy_cache`` in the
310+
current directory. While the cache is only read in incremental
311+
mode, it is written even in non-incremental mode, in order to "warm"
312+
the cache. To disable writing the cache, use
313+
``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul`` (Windows).
314+
Cache files belonging to a different mypy version are ignored.
315+
316+
.. _quick-mode:
317+
318+
- ``--quick-and-dirty`` is an experimental, unsafe variant of
319+
:ref:`incremental mode <incremental>`. Quick mode is faster than
320+
regular incremental mode, because it only re-checks modules that
321+
were modified since their cache file was last written (regular
322+
incremental mode also re-checks all modules that depend on one or
323+
more modules that were re-checked). Quick mode is unsafe because it
324+
may miss problems caused by a change in a dependency. Quick mode
325+
updates the cache, but regular incremental mode ignores cache files
326+
written by quick mode.
305327

306328
- ``--python-version X.Y`` will make mypy typecheck your code as if it were
307329
run under Python version X.Y. Without this option, mypy will default to using

docs/source/config_file.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@ The following global flags may only be set in the global section
9393
- ``dump_inference_stats`` (Boolean, default False) dumps stats about
9494
type inference.
9595

96-
- ``incremental`` (Boolean, default False) enables the experimental
97-
module cache.
96+
- ``incremental`` (Boolean, default False) enables :ref:`incremental
97+
mode <incremental>`.
9898

9999
- ``cache_dir`` (string, default ``.mypy_cache``) stores module cache
100-
info in the given folder in incremental mode.
100+
info in the given folder in :ref:`incremental mode <incremental>`.
101+
The cache is only read in incremental mode, but it is always written
102+
unless the value is set to ``/dev/null`` (UNIX) or ``nul``
103+
(Windows).
104+
105+
- ``quick_and_dirty`` (Boolean, default False) enables :ref:`quick
106+
mode <quick-mode>`.
101107

102108
- ``show_error_context`` (Boolean, default False) shows
103109
context notes before errors.

docs/source/function_overloading.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _function-overloading:
2+
13
Function Overloading
24
====================
35

@@ -20,7 +22,7 @@ You might be tempted to annotate it like so:
2022
... # Return a sequence of Ts here
2123
else:
2224
raise TypeError(...)
23-
25+
2426
But this is too loose, as it implies that when you pass in an ``int``
2527
you might sometimes get out a single item and sometimes a sequence.
2628
The return type depends on the parameter type in a way that can't be

docs/source/kinds_of_types.rst

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,132 @@ using bidirectional type inference:
188188
If you want to give the argument or return value types explicitly, use
189189
an ordinary, perhaps nested function definition.
190190

191+
.. _extended_callable:
192+
193+
Extended Callable types
194+
***********************
195+
196+
As an experimental mypy extension, you can specify ``Callable`` types
197+
that support keyword arguments, optional arguments, and more. Where
198+
you specify the arguments of a Callable, you can choose to supply just
199+
the type of a nameless positional argument, or an "argument specifier"
200+
representing a more complicated form of argument. This allows one to
201+
more closely emulate the full range of possibilities given by the
202+
``def`` statement in Python.
203+
204+
As an example, here's a complicated function definition and the
205+
corresponding ``Callable``:
206+
207+
.. code-block:: python
208+
209+
from typing import Callable
210+
from mypy_extensions import (Arg, DefaultArg, NamedArg,
211+
DefaultNamedArg, VarArg, KwArg)
212+
213+
def func(__a: int, # This convention is for nameless arguments
214+
b: int,
215+
c: int = 0,
216+
*args: int,
217+
d: int,
218+
e: int = 0,
219+
**kwargs: int) -> int:
220+
...
221+
222+
F = Callable[[int, # Or Arg(int)
223+
Arg(int, 'b'),
224+
DefaultArg(int, 'c'),
225+
VarArg(int),
226+
NamedArg(int, 'd'),
227+
DefaultNamedArg(int, 'e'),
228+
KwArg(int)],
229+
int]
230+
231+
f: F = func
232+
233+
Argument specifiers are special function calls that can specify the
234+
following aspects of an argument:
235+
236+
- its type (the only thing that the basic format supports)
237+
238+
- its name (if it has one)
239+
240+
- whether it may be omitted
241+
242+
- whether it may or must be passed using a keyword
243+
244+
- whether it is a ``*args`` argument (representing the remaining
245+
positional arguments)
246+
247+
- whether it is a ``**kwargs`` argument (representing the remaining
248+
keyword arguments)
249+
250+
The following functions are available in ``mypy_extensions`` for this
251+
purpose:
252+
253+
.. code-block:: python
254+
255+
def Arg(type=Any, name=None):
256+
# A normal, mandatory, positional argument.
257+
# If the name is specified it may be passed as a keyword.
258+
259+
def DefaultArg(type=Any, name=None):
260+
# An optional positional argument (i.e. with a default value).
261+
# If the name is specified it may be passed as a keyword.
262+
263+
def NamedArg(type=Any, name=None):
264+
# A mandatory keyword-only argument.
265+
266+
def DefaultNamedArg(type=Any, name=None):
267+
# An optional keyword-only argument (i.e. with a default value).
268+
269+
def VarArg(type=Any):
270+
# A *args-style variadic positional argument.
271+
# A single VarArg() specifier represents all remaining
272+
# positional arguments.
273+
274+
def KwArg(type=Any):
275+
# A **kwargs-style variadic keyword argument.
276+
# A single KwArg() specifier represents all remaining
277+
# keyword arguments.
278+
279+
In all cases, the ``type`` argument defaults to ``Any``, and if the
280+
``name`` argument is omitted the argument has no name (the name is
281+
required for ``NamedArg`` and ``DefaultNamedArg``). A basic
282+
``Callable`` such as
283+
284+
.. code-block:: python
285+
286+
MyFunc = Callable[[int, str, int], float]
287+
288+
is equivalent to the following:
289+
290+
.. code-block:: python
291+
292+
MyFunc = Callable[[Arg(int), Arg(str), Arg(int)], float]
293+
294+
A ``Callable`` with unspecified argument types, such as
295+
296+
.. code-block:: python
297+
298+
MyOtherFunc = Callable[..., int]
299+
300+
is (roughly) equivalent to
301+
302+
.. code-block:: python
303+
304+
MyOtherFunc = Callable[[VarArg(), KwArg()], int]
305+
306+
.. note::
307+
308+
This feature is experimental. Details of the implementation may
309+
change and there may be unknown limitations. **IMPORTANT:**
310+
Each of the functions above currently just returns its ``type``
311+
argument, so the information contained in the argument specifiers
312+
is not available at runtime. This limitation is necessary for
313+
backwards compatibility with the existing ``typing.py`` module as
314+
present in the Python 3.5+ standard library and distributed via
315+
PyPI.
316+
191317
.. _union-types:
192318

193319
Union types

docs/source/python36.rst

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ New features in Python 3.6
55

66
Python 3.6 was `released
77
<https://www.python.org/downloads/release/python-360/>`_ in
8-
December 2016. As of mypy 0.500 most language features new in Python
9-
3.6 are supported, with the exception of asynchronous generators and
10-
comprehensions.
8+
December 2016. As of mypy 0.510 all language features new in Python
9+
3.6 are supported.
1110

1211
Syntax for variable annotations (`PEP 526 <https://www.python.org/dev/peps/pep-0526>`_)
1312
---------------------------------------------------------------------------------------
@@ -17,6 +16,7 @@ now have type annotations using either of the two forms:
1716

1817
.. code-block:: python
1918
19+
from typing import Optional
2020
foo: Optional[int]
2121
bar: List[str] = []
2222
@@ -27,6 +27,29 @@ Mypy fully supports this syntax, interpreting them as equivalent to
2727
foo = None # type: Optional[int]
2828
bar = [] # type: List[str]
2929
30+
.. _class-var:
31+
32+
An additional feature defined in PEP 526 is also supported: you can
33+
mark names intended to be used as class variables with ``ClassVar``.
34+
In a pinch you can also use ClassVar in ``# type`` comments.
35+
Example:
36+
37+
.. code-block:: python
38+
39+
from typing import ClassVar
40+
41+
class C:
42+
x: int # instance variable
43+
y: ClassVar[int] # class variable
44+
z = None # type: ClassVar[int]
45+
46+
def foo(self) -> None:
47+
self.x = 0 # OK
48+
self.y = 0 # Error: Cannot assign to class variable "y" via instance
49+
50+
C.y = 0 # This is OK
51+
52+
3053
Literal string formatting (`PEP 498 <https://www.python.org/dev/peps/pep-0498>`_)
3154
---------------------------------------------------------------------------------
3255

@@ -50,22 +73,22 @@ Mypy fully supports this syntax:
5073
hexes: List[int] = []
5174
hexes.append(0x_FF_FF_FF_FF)
5275
53-
Asynchronous generators (`PEP 525 <https://www.python.org/dev/peps/pep-0525>`_)
54-
-------------------------------------------------------------------------------
76+
.. _async_generators_and_comprehensions:
5577

56-
Python 3.6 feature: coroutines defined with ``async def`` (PEP 492)
57-
can now also be generators, i.e. contain ``yield`` expressions.
78+
Asynchronous generators (`PEP 525 <https://www.python.org/dev/peps/pep-0525>`_) and comprehensions (`PEP 530 <https://www.python.org/dev/peps/pep-0530>`_)
79+
----------------------------------------------------------------------------------------------------------------------------------------------------------
5880

59-
Mypy does not yet support this.
81+
Python 3.6 allows coroutines defined with ``async def`` (PEP 492) to be
82+
generators, i.e. contain ``yield`` expressions, and introduces a syntax for
83+
asynchronous comprehensions. Mypy fully supports these features, for example:
6084

61-
Asynchronous comprehensions (`PEP 530 <https://www.python.org/dev/peps/pep-0530>`_)
62-
-----------------------------------------------------------------------------------
85+
.. code-block:: python
6386
64-
Python 3.6 feature: coroutines defined with ``async def`` (PEP 492)
65-
can now also contain list, set and dict comprehensions that use
66-
``async for`` syntax.
87+
from typing import AsyncIterator
6788
68-
Mypy does not yet support this.
89+
async def gen() -> AsyncIterator[bytes]:
90+
lst = [b async for b in gen()] # Inferred type is "List[bytes]"
91+
yield 'no way' # Error: Incompatible types (got "str", expected "bytes")
6992
7093
New named tuple syntax
7194
----------------------

docs/source/revision_history.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
Revision history
22
================
33

4-
List of major changes to this document:
4+
List of major changes:
55

6-
- April 2017
7-
* Remove option ``strict_boolean``.
6+
- May 2017
7+
* Publish ``mypy`` version 0.510 on PyPI.
8+
9+
* Remove option ``--no-fast-parser``.
10+
11+
* Deprecate option ``--strict-boolean``.
12+
13+
* Drop support for Python 3.2 as type checking target.
14+
15+
* Add support for :ref:`overloaded functions with implementations <function-overloading>`.
16+
17+
* Add :ref:`extended_callable`.
18+
19+
* Add :ref:`async_generators_and_comprehensions`.
20+
21+
* Add :ref:`ClassVar <class-var>`.
22+
23+
* Add :ref:`quick mode <quick-mode>`.
824

925
- March 2017
1026
* Publish ``mypy`` version 0.500 on PyPI.

0 commit comments

Comments
 (0)