Skip to content

Commit ec4dbc1

Browse files
authored
Merge pull request #1 from python/master
Sync Fork from Upstream Repo
2 parents 9bc4317 + 25c993b commit ec4dbc1

File tree

409 files changed

+92862
-8132
lines changed

Some content is hidden

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

409 files changed

+92862
-8132
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ include/
4343

4444
.tox
4545
pip-wheel-metadata
46+
47+
48+
test_capi
49+
*.o
50+
*.a
51+
test_capi
52+
/.mypyc-flake8-cache.json
53+
/mypyc/lib-rt/build/
54+
/mypyc/lib-rt/*.so

.travis.yml

+48-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ if: tag IS present OR type = pull_request OR ((branch = master OR branch =~ rele
44
language: python
55
# cache package wheels (1 cache per python version)
66
cache: pip
7+
# also cache the directories where we set up our custom pythons in some builds
8+
cache:
9+
directories:
10+
- $HOME/python-debug
11+
# I ran into some issues with this but will investigate again later.
12+
# - $HOME/.pyenv/versions
13+
- $HOME/Library/Caches/pip
14+
715
# newer python versions are available only on xenial (while some older only on trusty) Ubuntu distribution
816
dist: xenial
917

1018
env:
1119
TOXENV=py
1220
EXTRA_ARGS="-n 12"
1321
TEST_MYPYC=0
22+
PYTHON_DEBUG_BUILD=0
1423

1524
jobs:
1625
include:
@@ -22,14 +31,28 @@ jobs:
2231
python: 3.6 # 3.6.3 pip 9.0.1
2332
- name: "run test suite with python 3.7"
2433
python: 3.7 # 3.7.0 pip 10.0.1
34+
- name: "run test suite with python 3.8"
35+
python: 3.8
36+
- name: "run mypyc runtime tests with python 3.6 debug build"
37+
language: generic
38+
env:
39+
- TOXENV=py36
40+
- PYTHONVERSION=3.6.8
41+
- PYTHON_DEBUG_BUILD=1
42+
- EXTRA_ARGS="-n 12 mypyc/test/test_run.py mypyc/test/test_external.py"
43+
- name: "run mypyc runtime tests with python 3.6 on OS X"
44+
os: osx
45+
osx_image: xcode8.3
46+
language: generic
47+
env:
48+
- PYTHONVERSION=3.6.3
49+
- EXTRA_ARGS="-n 12 mypyc/test/test_run.py mypyc/test/test_external.py"
2550
- name: "run test suite with python 3.7 (compiled with mypyc)"
2651
python: 3.7
2752
env:
2853
- TOXENV=py
2954
- EXTRA_ARGS="-n 12"
3055
- TEST_MYPYC=1
31-
# - name: "run test suite with python 3.8-dev"
32-
# python: 3.8-dev
3356
- name: "type check our own code"
3457
python: 3.7
3558
env:
@@ -58,11 +81,33 @@ install:
5881
- pip install -U pip setuptools
5982
- pip install -U tox==3.9.0
6083
- tox --notest
84+
6185
# This is a big hack and only works because the layout of our directories
6286
# means that tox picks up the mypy from the source directories instead of
6387
# the version it installed into a venv. This is also *why* we need to do this,
6488
# since if we arranged for tox to build with mypyc, pytest wouldn't use it.
65-
- if [[ $TEST_MYPYC == 1 ]]; then pip install -r mypyc-requirements.txt; CC=clang MYPYC_OPT_LEVEL=0 python3 setup.py --use-mypyc build_ext --inplace; fi
89+
- if [[ $TEST_MYPYC == 1 ]]; then pip install -r mypy-requirements.txt; CC=clang MYPYC_OPT_LEVEL=0 python3 setup.py --use-mypyc build_ext --inplace; fi
6690

6791
script:
6892
- tox -- $EXTRA_ARGS
93+
94+
# Getting our hands on a debug build or the right OS X build is
95+
# annoying, unfortunately.
96+
before_install: |
97+
set -e
98+
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
99+
if [[ $PYTHON_DEBUG_BUILD == 1 ]]; then
100+
PYTHONDIR=~/python-debug/python-$PYTHONVERSION
101+
VENV=$PYTHONDIR/env
102+
misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV
103+
source $VENV/bin/activate
104+
fi
105+
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
106+
# Attempt to install, skipping if version already exists.
107+
pyenv install $PYTHONVERSION -s
108+
# Regenerate shims
109+
pyenv rehash
110+
# Manually set pyenv variables per https://pythonhosted.org/CodeChat/.travis.yml.html
111+
export PYENV_VERSION=$PYTHONVERSION
112+
export PATH="/Users/travis/.pyenv/shims:${PATH}"
113+
fi

LICENSE

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Mypy is licensed under the terms of the MIT license, reproduced below.
1+
Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced below.
22

33
= = = = =
44

55
The MIT License
66

7-
Copyright (c) 2015-2016 Jukka Lehtosalo and contributors
7+
Copyright (c) 2015-2019 Jukka Lehtosalo and contributors
88

99
Permission is hereby granted, free of charge, to any person obtaining a
1010
copy of this software and associated documentation files (the "Software"),
@@ -26,8 +26,10 @@ DEALINGS IN THE SOFTWARE.
2626

2727
= = = = =
2828

29-
Portions of mypy are licensed under different licenses. The files
30-
under stdlib-samples are licensed under the PSF 2 License, reproduced below.
29+
Portions of mypy and mypyc are licensed under different licenses. The
30+
files under stdlib-samples as well as the files
31+
mypyc/lib-rt/pythonsupport.h and mypyc/lib-rt/getargs.c are licensed
32+
under the PSF 2 License, reproduced below.
3133

3234
= = = = =
3335

@@ -223,5 +225,3 @@ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
223225
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
224226
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
225227
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
226-
227-
= = = = =

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ recursive-include extensions *
44
recursive-include docs *
55
recursive-include mypy/typeshed *.py *.pyi
66
recursive-include mypy/xml *.xsd *.xslt *.css
7+
recursive-include mypyc/lib-rt *.c *.h *.tmpl
78
include mypy_bootstrap.ini
89
include mypy_self_check.ini
910
include LICENSE

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,16 @@ IDE, Linter Integrations, and Pre-commit
110110

111111
Mypy can be integrated into popular IDEs:
112112

113-
* Vim: [syntastic](https://github.com/vim-syntastic/syntastic) in `.vimrc` add `let g:syntastic_python_checkers=['mypy']`
113+
* Vim:
114+
* Using [Syntastic](https://github.com/vim-syntastic/syntastic): in `~/.vimrc` add
115+
`let g:syntastic_python_checkers=['mypy']`
116+
* Using [ALE](https://github.com/dense-analysis/ale): should be enabled by default when `mypy` is installed,
117+
or can be explicitly enabled by adding `let b:ale_linters = ['mypy']` in `~/vim/ftplugin/python.vim`
114118
* Emacs: using [Flycheck](https://github.com/flycheck/) and [Flycheck-mypy](https://github.com/lbolla/emacs-flycheck-mypy)
115119
* Sublime Text: [SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
116120
* Atom: [linter-mypy](https://atom.io/packages/linter-mypy)
117-
* PyCharm: [mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin) (PyCharm integrates [its own implementation of PEP 484](https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html))
121+
* PyCharm: [mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin) (PyCharm integrates
122+
[its own implementation of PEP 484](https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html))
118123
* VS Code: provides [basic integration](https://code.visualstudio.com/docs/python/linting#_mypy) with mypy.
119124

120125
Mypy can also be integrated into [Flake8] using [flake8-mypy], or
@@ -216,7 +221,7 @@ This submodule contains types for the Python standard library.
216221

217222
Due to the way git submodules work, you'll have to do
218223
```
219-
git submodule update typeshed
224+
git submodule update mypy/typeshed
220225
```
221226
whenever you change branches, merge, rebase, or pull.
222227

@@ -264,10 +269,11 @@ in the typing gitter instead: https://gitter.im/python/typing
264269
Compiled version of mypy
265270
------------------------
266271

267-
We have built an compiled version of mypy using the [mypyc
268-
compiler](https://github.com/mypyc/mypyc) for mypy-annotated Python
269-
code. It is approximately 4 times faster than interpreted mypy and is
270-
available (and the default) for 64-bit Windows, macOS, and Linux.
272+
We have built a compiled version of mypy using the [mypyc
273+
compiler](https://github.com/python/mypy/tree/master/mypyc) for
274+
mypy-annotated Python code. It is approximately 4 times faster than
275+
interpreted mypy and is available (and the default) for 64-bit
276+
Windows, macOS, and Linux.
271277

272278
To install an interpreted mypy instead, use:
273279

appveyor.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ cache:
33

44
environment:
55
matrix:
6-
76
- PYTHON: "C:\\Python37-x64"
87
PYTHON_VERSION: "3.7.x"
98
PYTHON_ARCH: "64"
9+
EXTRA_ARGS:
10+
- PYTHON: "C:\\Python37"
11+
PYTHON_VERSION: "3.7.x"
12+
PYTHON_ARCH: "32"
13+
EXTRA_ARGS: "mypyc/test/test_run.py mypyc/test/test_external.py"
1014

1115
install:
1216
- "git submodule update --init mypy/typeshed"
@@ -16,7 +20,7 @@ install:
1620
build: off
1721

1822
test_script:
19-
- "%PYTHON%\\python.exe -m tox -e py37"
23+
- "%PYTHON%\\python.exe -m tox -e py37 %EXTRA_ARGS%"
2024

2125
skip_commits:
2226
files:

conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ def pytest_configure(config):
99
mypy_source_root = os.path.dirname(os.path.abspath(__file__))
1010
if os.getcwd() != mypy_source_root:
1111
os.chdir(mypy_source_root)
12+
13+
14+
# This function name is special to pytest. See
15+
# http://doc.pytest.org/en/latest/writing_plugins.html#initialization-command-line-and-configuration-hooks
16+
def pytest_addoption(parser) -> None:
17+
parser.addoption('--bench', action='store_true', default=False,
18+
help='Enable the benchmark test runs')

docs/source/additional_features.rst

+19-18
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ of the previous sections.
99
Dataclasses
1010
***********
1111

12-
In Python 3.7, a new ``dataclasses`` module has been added to the standard library.
12+
In Python 3.7, a new :py:mod:`dataclasses` module has been added to the standard library.
1313
This module allows defining and customizing simple boilerplate-free classes.
14-
They can be defined using the ``@dataclasses.dataclass`` decorator:
14+
They can be defined using the :py:func:`@dataclasses.dataclass
15+
<python:dataclasses.dataclass>` decorator:
1516

1617
.. code-block:: python
1718
@@ -25,7 +26,7 @@ They can be defined using the ``@dataclasses.dataclass`` decorator:
2526
test = Application("Testing...") # OK
2627
bad = Application("Testing...", "with plugin") # Error: List[str] expected
2728
28-
Mypy will detect special methods (such as ``__lt__``) depending on the flags used to
29+
Mypy will detect special methods (such as :py:meth:`__lt__ <object.__lt__>`) depending on the flags used to
2930
define dataclasses. For example:
3031

3132
.. code-block:: python
@@ -65,16 +66,16 @@ class can be used:
6566
6667
val = unbox(BoxedData(42, "<important>")) # OK, inferred type is int
6768
68-
For more information see `official docs <https://docs.python.org/3/library/dataclasses.html>`_
69-
and `PEP 557 <https://www.python.org/dev/peps/pep-0557/>`_.
69+
For more information see :doc:`official docs <python:library/dataclasses>`
70+
and :pep:`557`.
7071

7172
Caveats/Known Issues
7273
====================
7374

74-
Some functions in the ``dataclasses`` module, such as ``replace()`` and ``asdict()``,
75+
Some functions in the :py:mod:`dataclasses` module, such as :py:func:`~dataclasses.replace` and :py:func:`~dataclasses.asdict`,
7576
have imprecise (too permissive) types. This will be fixed in future releases.
7677

77-
Mypy does not yet recognize aliases of ``dataclasses.dataclass``, and will
78+
Mypy does not yet recognize aliases of :py:func:`dataclasses.dataclass <dataclasses.dataclass>`, and will
7879
probably never recognize dynamically computed decorators. The following examples
7980
do **not** work:
8081

@@ -110,7 +111,7 @@ do **not** work:
110111
The attrs package
111112
*****************
112113

113-
`attrs <http://www.attrs.org/en/stable>`_ is a package that lets you define
114+
:doc:`attrs <attrs:index>` is a package that lets you define
114115
classes without writing boilerplate code. Mypy can detect uses of the
115116
package and will generate the necessary method definitions for decorated
116117
classes using the type annotations it finds.
@@ -139,7 +140,7 @@ If you're using ``auto_attribs=True`` you must use variable annotations.
139140
three: int = attr.ib(8)
140141
141142
Typeshed has a couple of "white lie" annotations to make type checking
142-
easier. ``attr.ib`` and ``attr.Factory`` actually return objects, but the
143+
easier. :py:func:`attr.ib` and :py:class:`attr.Factory` actually return objects, but the
143144
annotation says these return the types that they expect to be assigned to.
144145
That enables this to work:
145146

@@ -174,9 +175,9 @@ Caveats/Known Issues
174175
175176
* Currently, ``converter`` only supports named functions. If mypy finds something else it
176177
will complain about not understanding the argument and the type annotation in
177-
``__init__`` will be replaced by ``Any``.
178+
:py:meth:`__init__ <object.__init__>` will be replaced by ``Any``.
178179

179-
* `Validator decorators <http://www.attrs.org/en/stable/examples.html#validators>`_
180+
* :ref:`Validator decorators <attrs:examples_validators>`
180181
and `default decorators <http://www.attrs.org/en/stable/examples.html#defaults>`_
181182
are not type-checked against the attribute they are setting/validating.
182183

@@ -285,7 +286,7 @@ run after starting or restarting the daemon.
285286

286287
The mypy daemon requires extra fine-grained dependency data in
287288
the cache files which aren't included by default. To use caching with
288-
the mypy daemon, use the ``--cache-fine-grained`` option in your CI
289+
the mypy daemon, use the :option:`--cache-fine-grained <mypy --cache-fine-grained>` option in your CI
289290
build::
290291

291292
$ mypy --cache-fine-grained <args...>
@@ -325,7 +326,7 @@ at least if your codebase is hundreds of thousands of lines or more:
325326
network), the script can still fall back to a normal incremental build.
326327

327328
* You can have multiple local cache directories for different local branches
328-
using the ``--cache-dir`` option. If the user switches to an existing
329+
using the :option:`--cache-dir <mypy --cache-dir>` option. If the user switches to an existing
329330
branch where downloaded cache data is already available, you can continue
330331
to use the existing cache data instead of redownloading the data.
331332

@@ -347,16 +348,16 @@ Extended Callable types
347348
This feature is deprecated. You can use
348349
:ref:`callback protocols <callback_protocols>` as a replacement.
349350

350-
As an experimental mypy extension, you can specify ``Callable`` types
351+
As an experimental mypy extension, you can specify :py:data:`~typing.Callable` types
351352
that support keyword arguments, optional arguments, and more. When
352-
you specify the arguments of a Callable, you can choose to supply just
353+
you specify the arguments of a :py:data:`~typing.Callable`, you can choose to supply just
353354
the type of a nameless positional argument, or an "argument specifier"
354355
representing a more complicated form of argument. This allows one to
355356
more closely emulate the full range of possibilities given by the
356357
``def`` statement in Python.
357358

358359
As an example, here's a complicated function definition and the
359-
corresponding ``Callable``:
360+
corresponding :py:data:`~typing.Callable`:
360361

361362
.. code-block:: python
362363
@@ -433,7 +434,7 @@ purpose:
433434
In all cases, the ``type`` argument defaults to ``Any``, and if the
434435
``name`` argument is omitted the argument has no name (the name is
435436
required for ``NamedArg`` and ``DefaultNamedArg``). A basic
436-
``Callable`` such as
437+
:py:data:`~typing.Callable` such as
437438

438439
.. code-block:: python
439440
@@ -445,7 +446,7 @@ is equivalent to the following:
445446
446447
MyFunc = Callable[[Arg(int), Arg(str), Arg(int)], float]
447448
448-
A ``Callable`` with unspecified argument types, such as
449+
A :py:data:`~typing.Callable` with unspecified argument types, such as
449450

450451
.. code-block:: python
451452

docs/source/builtin_types.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Type Description
2323
====================== ===============================
2424

2525
The type ``Any`` and type constructors such as ``List``, ``Dict``,
26-
``Iterable`` and ``Sequence`` are defined in the ``typing`` module.
26+
``Iterable`` and ``Sequence`` are defined in the :py:mod:`typing` module.
2727

2828
The type ``Dict`` is a *generic* class, signified by type arguments within
2929
``[...]``. For example, ``Dict[int, str]`` is a dictionary from integers to
@@ -35,6 +35,6 @@ strings and ``Dict[Any, Any]`` is a dictionary of dynamically typed
3535
correspond to Python protocols. For example, a ``str`` object or a
3636
``List[str]`` object is valid
3737
when ``Iterable[str]`` or ``Sequence[str]`` is expected. Note that even though
38-
they are similar to abstract base classes defined in ``collections.abc``
38+
they are similar to abstract base classes defined in :py:mod:`collections.abc`
3939
(formerly ``collections``), they are not identical, since the built-in
4040
collection type objects do not support indexing.

docs/source/casts.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Casts and type assertions
66
Mypy supports type casts that are usually used to coerce a statically
77
typed value to a subtype. Unlike languages such as Java or C#,
88
however, mypy casts are only used as hints for the type checker, and they
9-
don't perform a runtime type check. Use the function ``cast`` to perform a
9+
don't perform a runtime type check. Use the function :py:func:`~typing.cast` to perform a
1010
cast:
1111

1212
.. code-block:: python

docs/source/cheat_sheet.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Type hints cheat sheet (Python 2)
44
=================================
55

6-
This document is a quick cheat sheet showing how the
7-
`PEP 484 <https://www.python.org/dev/peps/pep-0484/>`_ type
6+
This document is a quick cheat sheet showing how the :pep:`484` type
87
language represents various common types in Python 2.
98

109
.. note::

0 commit comments

Comments
 (0)