Skip to content

Commit 74277c9

Browse files
Merge branch 'master' into asyncgen
2 parents f155c65 + 1ed4cb6 commit 74277c9

Some content is hidden

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

88 files changed

+4471
-1353
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ If you want to run the latest version of the code, you can install from git:
8383

8484

8585
Now, if Python on your system is configured properly (else see
86-
"Troubleshooting" below), you can type-check a program like this:
86+
"Troubleshooting" below), you can type-check the [statically typed parts] of a
87+
program like this:
8788

8889
$ mypy PROGRAM
8990

@@ -92,6 +93,8 @@ programs, even if they have type errors:
9293

9394
$ python3 PROGRAM
9495

96+
[statically typed parts]: http://mypy.readthedocs.io/en/latest/basics.html#function-signatures
97+
9598

9699
Web site and documentation
97100
--------------------------

appveyor.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ install:
2626
build: off
2727

2828
test_script:
29-
# Ignore lint (it's run separately below), reports (since we don't have lxml),
30-
# and cmdline (since one of its tests depend on lxml)
31-
- "%PYTHON%\\python.exe runtests.py -x lint -x reports -x cmdline"
29+
# Ignore lint (it's run separately below)
30+
- "%PYTHON%\\python.exe runtests.py -x lint"
3231
- ps: if ($env:PYTHON_VERSION -Match "3.6.x" -And $env:PYTHON_ARCH -Match "64") { iex "$env:PYTHON\\python.exe -m flake8" }

docs/source/command_line.rst

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ flag (or its long form ``--help``)::
1616
[--warn-incomplete-stub] [--warn-redundant-casts]
1717
[--warn-no-return] [--warn-unused-ignores] [--show-error-context]
1818
[--fast-parser] [-i] [--cache-dir DIR] [--strict-optional]
19-
[--strict-optional-whitelist [GLOB [GLOB ...]]]
19+
[--strict-optional-whitelist [GLOB [GLOB ...]]] [--strict]
2020
[--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats]
2121
[--inferstats] [--custom-typing MODULE]
2222
[--custom-typeshed-dir DIR] [--scripts-are-modules]
2323
[--config-file CONFIG_FILE] [--show-column-numbers]
24-
[--find-occurrences CLASS.MEMBER] [--cobertura-xml-report DIR]
25-
[--html-report DIR] [--linecount-report DIR]
26-
[--linecoverage-report DIR] [--memory-xml-report DIR]
27-
[--old-html-report DIR] [--txt-report DIR] [--xml-report DIR]
28-
[--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE]
29-
[-c PROGRAM_TEXT] [-p PACKAGE]
24+
[--find-occurrences CLASS.MEMBER] [--strict-boolean]
25+
[--cobertura-xml-report DIR] [--html-report DIR]
26+
[--linecount-report DIR] [--linecoverage-report DIR]
27+
[--memory-xml-report DIR] [--old-html-report DIR]
28+
[--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR]
29+
[--xslt-txt-report DIR] [-m MODULE] [-c PROGRAM_TEXT] [-p PACKAGE]
3030
[files [files ...]]
3131

3232
(etc., too long to show everything here)
@@ -345,9 +345,9 @@ Here are some more useful flags:
345345

346346
- ``--config-file CONFIG_FILE`` causes configuration settings to be
347347
read from the given file. By default settings are read from ``mypy.ini``
348-
in the current directory. Settings override mypy's built-in defaults
349-
and command line flags can override settings. See :ref:`config-file`
350-
for the syntax of configuration files.
348+
or ``setup.cfg`` in the current directory. Settings override mypy's
349+
built-in defaults and command line flags can override settings.
350+
See :ref:`config-file` for the syntax of configuration files.
351351

352352
- ``--junit-xml JUNIT_XML`` will make mypy generate a JUnit XML test
353353
result document with type checking results. This can make it easier
@@ -366,6 +366,17 @@ Here are some more useful flags:
366366
also currently ignores functions with an empty body or a body that is
367367
just ellipsis (``...``), since these can be valid as abstract methods.
368368

369+
- ``--warn-return-any`` causes mypy to generate a warning when returning a value
370+
with type ``Any`` from a function declared with a non- ``Any`` return type.
371+
372+
- ``--strict-boolean`` will make using non-boolean expressions in conditions
373+
an error. This means ``if x`` and ``while x`` are disallowed when ``x`` has any
374+
type other than ``bool``. Instead use explicit checks like ``if x > 0`` or
375+
``while x is not None``.
376+
377+
- ``--strict`` mode enables all optional error checking flags. You can see the
378+
list of flags enabled by strict mode in the full ``mypy -h`` output.
379+
369380
For the remaining flags you can read the full ``mypy -h`` output.
370381

371382
.. note::
@@ -378,20 +389,21 @@ Integrating mypy into another Python application
378389
************************************************
379390

380391
It is possible to integrate mypy into another Python 3 application by
381-
importing ``mypy.api`` and calling the ``run`` function with exactly the string
382-
you would have passed to mypy from the command line.
392+
importing ``mypy.api`` and calling the ``run`` function with a parameter of type ``List[str]``, containing
393+
what normally would have been the command line arguments to mypy.
383394

384-
Function ``run`` returns a tuple of strings:
385-
``(<normal_report>, <error_report>)``, in which ``<normal_report>`` is what mypy
386-
normally writes to ``sys.stdout`` and ``<error_report>`` is what mypy normally
387-
writes to ``sys.stderr``.
395+
Function ``run`` returns a ``Tuple[str, str, int]``, namely
396+
``(<normal_report>, <error_report>, <exit_status>)``, in which ``<normal_report>``
397+
is what mypy normally writes to ``sys.stdout``, ``<error_report>`` is what mypy
398+
normally writes to ``sys.stderr`` and ``exit_status`` is the exit status mypy normally
399+
returns to the operating system.
388400

389-
A trivial example of this is the following::
401+
A trivial example of using the api is the following::
390402

391403
import sys
392404
from mypy import api
393405

394-
result = api.run(' '.join(sys.argv[1:]))
406+
result = api.run(sys.argv[1:])
395407

396408
if result[0]:
397409
print('\nType checking report:\n')
@@ -400,3 +412,5 @@ A trivial example of this is the following::
400412
if result[1]:
401413
print('\nError report:\n')
402414
print(result[1]) # stderr
415+
416+
print ('\nExit status:', result[2])

docs/source/config_file.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ The mypy configuration file
44
===========================
55

66
Mypy supports reading configuration settings from a file. By default
7-
it uses the file ``mypy.ini`` in the current directory; the
8-
``--config-file`` command-line flag can be used to read a different
9-
file instead (see :ref:`--config-file <config-file-flag>`).
7+
it uses the file ``mypy.ini`` (with fallback to ``setup.cfg``) in the
8+
current directory; the ``--config-file`` command-line flag can be used to
9+
read a different file instead (see :ref:`--config-file <config-file-flag>`).
10+
11+
It is important to understand that there is no merging of configuration
12+
files, as it would lead to ambiguity. The ``--config-file`` flag
13+
has the highest precedence and must be correct; otherwise mypy will report
14+
an error and exit. Without command line option, mypy will look for defaults,
15+
but will use only one of them. The first one to read is ``mypy.ini``,
16+
and then ``setup.cfg``.
1017

1118
Most flags correspond closely to :ref:`command-line flags
1219
<command-line>` but there are some differences in flag names and some
@@ -19,7 +26,7 @@ settings of the form `NAME = VALUE`. Comments start with ``#``
1926
characters.
2027

2128
- A section named ``[mypy]`` must be present. This specifies
22-
the global flags.
29+
the global flags. The ``setup.cfg`` file is an exception to this.
2330

2431
- Additional sections named ``[mypy-PATTERN1,PATTERN2,...]`` may be
2532
present, where ``PATTERN1``, ``PATTERN2`` etc. are `fnmatch patterns
@@ -161,6 +168,11 @@ overridden by the pattern sections matching the module name.
161168
- ``warn_no_return`` (Boolean, default False) shows errors for
162169
missing return statements on some execution paths.
163170

171+
- ``warn_return_any`` (Boolean, default False) shows a warning when
172+
returning a value with type ``Any`` from a function declared with a
173+
non- ``Any`` return type.
174+
175+
164176
Example
165177
*******
166178

lib-typing/2.7/mod_generics_cache.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Module for testing the behavior of generics across different modules."""
2+
3+
from typing import TypeVar, Generic
4+
5+
T = TypeVar('T')
6+
7+
8+
class A(Generic[T]):
9+
pass
10+
11+
12+
class B(Generic[T]):
13+
class A(Generic[T]):
14+
pass

0 commit comments

Comments
 (0)