Skip to content

Commit 2a37e80

Browse files
committed
Merge branch 'master' into import-cycle
* master: (27 commits) Don't call --strict-optional and --incremental experimental (python#4642) Sync typeshed (python#4641) Fix callable types with inconsistent argument counts (python#4611) Fix example (add 'class A:') Make psutil an optional dependency (python#4634) mypy and mypy_extensions aren't posix only (python#3765) Documentation for attr support (python#4632) Use read_with_python_encoding in stubgen to handle file encoding (python#3790) Sync typeshed (python#4631) Add remaining core team emails to CREDITS (python#4629) Fix issues with attr code. (python#4628) Better support for converter in attrs plugin. (python#4607) Clean up credits (python#4626) Support type aliases in fine-grained incremental mode (python#4525) Fine-grained: Fix crash caused by unreachable class (python#4613) Treat divmod like a binary operator (python#4585) Sync typeshed (python#4605) Fine-grained: Don't infer partial types from multiple targets (python#4553) Fine-grained: Compare symbol table snapshots when following dependencies (python#4598) Fix type of forward reference to a decorated class method (python#4486) ...
2 parents b5bf41d + 064c8d3 commit 2a37e80

Some content is hidden

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

52 files changed

+4259
-264
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ For every pull request, we aim to promptly either merge it or say why
8080
it's not yet ready; if you go a few days without a reply, please feel
8181
free to ping the thread by adding a new comment.
8282

83-
At present the core developers are (alphabetically):
84-
* David Fisher (@ddfisher)
85-
* Jukka Lehtosalo (@JukkaL)
86-
* Greg Price (@gnprice)
87-
* Guido van Rossum (@gvanrossum)
83+
For a list of mypy core developers, see the file [CREDITS](CREDITS).
8884

8985

9086
Preparing Changes

CREDITS

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ https://github.com/python/mypy/commits/master
77
For lists of contributors per mypy release (including typeshed) see
88
the release blog posts at https://mypy-lang.blogspot.com/.
99

10-
Mypy team:
10+
Dropbox core team:
1111

1212
Jukka Lehtosalo <[email protected]>
1313
Guido van Rossum <[email protected]>
14-
Ivan Levkivskyi
15-
Michael J. Sullivan
14+
Ivan Levkivskyi <[email protected]>
15+
Michael J. Sullivan <[email protected]>
16+
17+
Non-Dropbox core team members:
18+
19+
Ethan Smith
20+
Jelle Zijlstra
1621

1722
Past Dropbox core team members:
1823

@@ -23,11 +28,6 @@ Past Dropbox core team members:
2328
Michael Lee
2429
Reid Barton
2530

26-
Non-Dropbox core team members:
27-
28-
Ethan Smith
29-
Jelle Zijlstra
30-
3131
Additional thanks to:
3232

3333
Alex Allain

docs/source/additional_features.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,79 @@ including the following:
77
- inheritance between generic classes
88
- compatibility and subtyping of generic types, including covariance of generic types
99
- ``super()``
10+
11+
12+
.. _attrs_package:
13+
14+
The attrs package
15+
*****************
16+
17+
`attrs <https://www.attrs.org/en/stable>`_ is a package that lets you define
18+
classes without writing boilerplate code. Mypy can detect uses of the
19+
package and will generate the necessary method definitions for decorated
20+
classes using the type annotations it finds.
21+
Type annotations can be added as follows:
22+
23+
.. code-block:: python
24+
25+
import attr
26+
@attr.s
27+
class A:
28+
one: int = attr.ib() # Variable annotation (Python 3.6+)
29+
two = attr.ib() # type: int # Type comment
30+
three = attr.ib(type=int) # type= argument
31+
32+
If you're using ``auto_attribs=True`` you must use variable annotations.
33+
34+
.. code-block:: python
35+
36+
import attr
37+
@attr.s(auto_attribs=True)
38+
class A:
39+
one: int
40+
two: int = 7
41+
three: int = attr.ib(8)
42+
43+
Typeshed has a couple of "white lie" annotations to make type checking
44+
easier. ``attr.ib`` and ``attr.Factory`` actually return objects, but the
45+
annotation says these return the types that they expect to be assigned to.
46+
That enables this to work:
47+
48+
.. code-block:: python
49+
50+
import attr
51+
from typing import Dict
52+
@attr.s(auto_attribs=True)
53+
class A:
54+
one: int = attr.ib(8)
55+
two: Dict[str, str] = attr.Factory(dict)
56+
bad: str = attr.ib(16) # Error: can't assign int to str
57+
58+
Caveats/Known Issues
59+
====================
60+
61+
* The detection of attr classes and attributes works by function name only.
62+
This means that if you have your own helper functions that, for example,
63+
``return attr.ib()`` mypy will not see them.
64+
65+
* All boolean arguments that mypy cares about must be literal ``True`` or ``False``.
66+
e.g the following will not work:
67+
68+
.. code-block:: python
69+
70+
import attr
71+
YES = True
72+
@attr.s(init=YES)
73+
class A:
74+
...
75+
76+
* Currently, ``converter`` only supports named functions. If mypy finds something else it
77+
will complain about not understanding the argument and the type annotation in
78+
``__init__`` will be replaced by ``Any``.
79+
80+
* `Validator decorators <http://www.attrs.org/en/stable/examples.html#decorator>`_
81+
and `default decorators <http://www.attrs.org/en/stable/examples.html#defaults>`_
82+
are not type-checked against the attribute they are setting/validating.
83+
84+
* Method definitions added by mypy currently overwrite any existing method
85+
definitions.

docs/source/command_line.rst

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,11 @@ Here are some more useful flags:
292292
- ``--ignore-missing-imports`` suppresses error messages about imports
293293
that cannot be resolved (see :ref:`follow-imports` for some examples).
294294

295-
- ``--strict-optional`` enables experimental strict checking of ``Optional[...]``
296-
types and ``None`` values. Without this option, mypy doesn't generally check the
297-
use of ``None`` values -- they are valid everywhere. See :ref:`strict_optional` for
298-
more about this feature.
299-
300-
- ``--strict-optional-whitelist`` attempts to suppress strict Optional-related
301-
errors in non-whitelisted files. Takes an arbitrary number of globs as the
302-
whitelist. This option is intended to be used to incrementally roll out
303-
``--strict-optional`` to a large codebase that already has mypy annotations.
304-
However, this flag comes with some significant caveats. It does not suppress
305-
all errors caused by turning on ``--strict-optional``, only most of them, so
306-
there may still be a bit of upfront work to be done before it can be used in
307-
CI. It will also suppress some errors that would be caught in a
308-
non-strict-Optional run. Therefore, when using this flag, you should also
309-
re-check your code without ``--strict-optional`` to ensure new type errors
310-
are not introduced.
295+
- ``--strict-optional`` enables strict checking of ``Optional[...]``
296+
types and ``None`` values. Without this option, mypy doesn't
297+
generally check the use of ``None`` values -- they are valid
298+
everywhere. See :ref:`strict_optional` for more about this feature.
299+
This flag will become the default in the near future.
311300

312301
- ``--disallow-untyped-defs`` reports an error whenever it encounters
313302
a function definition without type annotations.
@@ -342,17 +331,19 @@ Here are some more useful flags:
342331

343332
.. _incremental:
344333

345-
- ``--incremental`` is an experimental option that enables a module
346-
cache. When enabled, mypy caches results from previous runs
347-
to speed up type checking. Incremental mode can help when most parts
348-
of your program haven't changed since the previous mypy run. A
349-
companion flag is ``--cache-dir DIR``, which specifies where the
350-
cache files are written. By default this is ``.mypy_cache`` in the
351-
current directory. While the cache is only read in incremental
352-
mode, it is written even in non-incremental mode, in order to "warm"
353-
the cache. To disable writing the cache, use
354-
``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul`` (Windows).
355-
Cache files belonging to a different mypy version are ignored.
334+
- ``--incremental`` enables a module cache, using results from
335+
previous runs to speed up type checking. Incremental mode can help
336+
when most parts of your program haven't changed since the previous
337+
mypy run.
338+
339+
- ``--cache-dir DIR`` is a companion flag to ``-incremental``, which
340+
specifies where the cache files are written. By default this is
341+
``.mypy_cache`` in the current directory. While the cache is only
342+
read in incremental mode, it is written even in non-incremental
343+
mode, in order to "warm" the cache. To disable writing the cache,
344+
use ``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul``
345+
(Windows). Cache files belonging to a different mypy version are
346+
ignored.
356347

357348
.. _quick-mode:
358349

docs/source/kinds_of_types.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,14 @@ idiomatic.
432432

433433
.. _strict_optional:
434434

435-
Experimental strict optional type and None checking
435+
Strict optional type and None checking
436436
***************************************************
437437

438438
Currently, ``None`` is a valid value for each type, similar to
439439
``null`` or ``NULL`` in many languages. However, you can use the
440-
experimental ``--strict-optional`` command line option to tell mypy
441-
that types should not include ``None``
440+
``--strict-optional`` command line option
441+
(which will become the default in the near future)
442+
to tell mypy that types should not include ``None``
442443
by default. The ``Optional`` type modifier is then used to define
443444
a type variant that includes ``None``, such as ``Optional[int]``:
444445

@@ -478,10 +479,6 @@ recognizes ``is None`` checks:
478479
Mypy will infer the type of ``x`` to be ``int`` in the else block due to the
479480
check against ``None`` in the if condition.
480481

481-
.. note::
482-
483-
``--strict-optional`` is experimental and still has known issues.
484-
485482
.. _noreturn:
486483

487484
The NoReturn type
@@ -986,7 +983,7 @@ annotated the first example as the following:
986983
def squares(n: int) -> Generator[int, None, None]:
987984
for i in range(n):
988985
yield i * i
989-
986+
990987
This is slightly different from using ``Iterable[int]`` or ``Iterator[int]``,
991988
since generators have ``close()``, ``send()``, and ``throw()`` methods that
992989
generic iterables don't. If you will call these methods on the returned

extensions/setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
'Environment :: Console',
1818
'Intended Audience :: Developers',
1919
'License :: OSI Approved :: MIT License',
20-
'Operating System :: POSIX',
2120
'Programming Language :: Python :: 2',
2221
'Programming Language :: Python :: 2.7',
2322
'Programming Language :: Python :: 3',
@@ -37,7 +36,6 @@
3736
author_email='[email protected]',
3837
url='http://www.mypy-lang.org/',
3938
license='MIT License',
40-
platforms=['POSIX'],
4139
py_modules=['mypy_extensions'],
4240
classifiers=classifiers,
4341
install_requires=[

0 commit comments

Comments
 (0)