Skip to content

Commit

Permalink
Merge branch 'master' into import-cycle
Browse files Browse the repository at this point in the history
* 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)
  ...
  • Loading branch information
carljm committed Feb 28, 2018
2 parents b5bf41d + 064c8d3 commit 2a37e80
Show file tree
Hide file tree
Showing 52 changed files with 4,259 additions and 264 deletions.
6 changes: 1 addition & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ For every pull request, we aim to promptly either merge it or say why
it's not yet ready; if you go a few days without a reply, please feel
free to ping the thread by adding a new comment.

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


Preparing Changes
Expand Down
16 changes: 8 additions & 8 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ https://github.com/python/mypy/commits/master
For lists of contributors per mypy release (including typeshed) see
the release blog posts at https://mypy-lang.blogspot.com/.

Mypy team:
Dropbox core team:

Jukka Lehtosalo <[email protected]>
Guido van Rossum <[email protected]>
Ivan Levkivskyi
Michael J. Sullivan
Ivan Levkivskyi <[email protected]>
Michael J. Sullivan <[email protected]>

Non-Dropbox core team members:

Ethan Smith
Jelle Zijlstra

Past Dropbox core team members:

Expand All @@ -23,11 +28,6 @@ Past Dropbox core team members:
Michael Lee
Reid Barton

Non-Dropbox core team members:

Ethan Smith
Jelle Zijlstra

Additional thanks to:

Alex Allain
Expand Down
76 changes: 76 additions & 0 deletions docs/source/additional_features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,79 @@ including the following:
- inheritance between generic classes
- compatibility and subtyping of generic types, including covariance of generic types
- ``super()``


.. _attrs_package:

The attrs package
*****************

`attrs <https://www.attrs.org/en/stable>`_ is a package that lets you define
classes without writing boilerplate code. Mypy can detect uses of the
package and will generate the necessary method definitions for decorated
classes using the type annotations it finds.
Type annotations can be added as follows:

.. code-block:: python
import attr
@attr.s
class A:
one: int = attr.ib() # Variable annotation (Python 3.6+)
two = attr.ib() # type: int # Type comment
three = attr.ib(type=int) # type= argument
If you're using ``auto_attribs=True`` you must use variable annotations.

.. code-block:: python
import attr
@attr.s(auto_attribs=True)
class A:
one: int
two: int = 7
three: int = attr.ib(8)
Typeshed has a couple of "white lie" annotations to make type checking
easier. ``attr.ib`` and ``attr.Factory`` actually return objects, but the
annotation says these return the types that they expect to be assigned to.
That enables this to work:

.. code-block:: python
import attr
from typing import Dict
@attr.s(auto_attribs=True)
class A:
one: int = attr.ib(8)
two: Dict[str, str] = attr.Factory(dict)
bad: str = attr.ib(16) # Error: can't assign int to str
Caveats/Known Issues
====================

* The detection of attr classes and attributes works by function name only.
This means that if you have your own helper functions that, for example,
``return attr.ib()`` mypy will not see them.

* All boolean arguments that mypy cares about must be literal ``True`` or ``False``.
e.g the following will not work:

.. code-block:: python
import attr
YES = True
@attr.s(init=YES)
class A:
...
* Currently, ``converter`` only supports named functions. If mypy finds something else it
will complain about not understanding the argument and the type annotation in
``__init__`` will be replaced by ``Any``.

* `Validator decorators <http://www.attrs.org/en/stable/examples.html#decorator>`_
and `default decorators <http://www.attrs.org/en/stable/examples.html#defaults>`_
are not type-checked against the attribute they are setting/validating.

* Method definitions added by mypy currently overwrite any existing method
definitions.
45 changes: 18 additions & 27 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,11 @@ Here are some more useful flags:
- ``--ignore-missing-imports`` suppresses error messages about imports
that cannot be resolved (see :ref:`follow-imports` for some examples).

- ``--strict-optional`` enables experimental strict checking of ``Optional[...]``
types and ``None`` values. Without this option, mypy doesn't generally check the
use of ``None`` values -- they are valid everywhere. See :ref:`strict_optional` for
more about this feature.

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

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

.. _incremental:

- ``--incremental`` is an experimental option that enables a module
cache. When enabled, mypy caches results from previous runs
to speed up type checking. Incremental mode can help when most parts
of your program haven't changed since the previous mypy run. A
companion flag is ``--cache-dir DIR``, which specifies where the
cache files are written. By default this is ``.mypy_cache`` in the
current directory. While the cache is only read in incremental
mode, it is written even in non-incremental mode, in order to "warm"
the cache. To disable writing the cache, use
``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul`` (Windows).
Cache files belonging to a different mypy version are ignored.
- ``--incremental`` enables a module cache, using results from
previous runs to speed up type checking. Incremental mode can help
when most parts of your program haven't changed since the previous
mypy run.

- ``--cache-dir DIR`` is a companion flag to ``-incremental``, which
specifies where the cache files are written. By default this is
``.mypy_cache`` in the current directory. While the cache is only
read in incremental mode, it is written even in non-incremental
mode, in order to "warm" the cache. To disable writing the cache,
use ``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul``
(Windows). Cache files belonging to a different mypy version are
ignored.

.. _quick-mode:

Expand Down
13 changes: 5 additions & 8 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,14 @@ idiomatic.

.. _strict_optional:

Experimental strict optional type and None checking
Strict optional type and None checking
***************************************************

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

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

.. note::

``--strict-optional`` is experimental and still has known issues.

.. _noreturn:

The NoReturn type
Expand Down Expand Up @@ -986,7 +983,7 @@ annotated the first example as the following:
def squares(n: int) -> Generator[int, None, None]:
for i in range(n):
yield i * i
This is slightly different from using ``Iterable[int]`` or ``Iterator[int]``,
since generators have ``close()``, ``send()``, and ``throw()`` methods that
generic iterables don't. If you will call these methods on the returned
Expand Down
2 changes: 0 additions & 2 deletions extensions/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
Expand All @@ -37,7 +36,6 @@
author_email='[email protected]',
url='http://www.mypy-lang.org/',
license='MIT License',
platforms=['POSIX'],
py_modules=['mypy_extensions'],
classifiers=classifiers,
install_requires=[
Expand Down
Loading

0 comments on commit 2a37e80

Please sign in to comment.