Loading PKG-INFO +1 −1 Original line number Diff line number Diff line Metadata-Version: 2.1 Name: mypy Version: 0.580 Version: 0.590 Summary: Optional static typing for Python Home-page: http://www.mypy-lang.org/ Author: Jukka Lehtosalo Loading docs/source/cheat_sheet_py3.rst +39 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,45 @@ Python 3 introduces an annotation syntax for function declarations in `PEP 3107 ... Coroutines and asyncio ********************** See :ref:`async-and-await` for the full detail on typing coroutines and asynchronous code. .. code-block:: python import asyncio from typing import Generator, Any # A generator-based coroutine created with @asyncio.coroutine should have a # return type of Generator[Any, None, T], where T is the type it returns. @asyncio.coroutine def countdown34(tag: str, count: int) -> Generator[Any, None, str]: while count > 0: print('T-minus {} ({})'.format(count, tag)) yield from asyncio.sleep(0.1) count -= 1 return "Blastoff!" # mypy currently does not support converting functions into generator-based # coroutines in Python 3.4, so you need to add a 'yield' to make it # typecheck. @asyncio.coroutine def async1(obj: object) -> Generator[None, None, str]: if False: yield return "placeholder" # A Python 3.5+ coroutine is typed like a normal function. async def countdown35(tag: str, count: int) -> str: while count > 0: print('T-minus {} ({})'.format(count, tag)) await asyncio.sleep(0.1) count -= 1 return "Blastoff!" async def async2(obj: object) -> str: return "placeholder" When you're puzzled or when things are complicated ************************************************** Loading docs/source/class_basics.rst +8 −3 Original line number Diff line number Diff line Loading @@ -309,10 +309,13 @@ This is a type for objects that support ``bytes(x)``. def __bytes__(self) -> bytes .. _supports-int-etc: ``SupportsComplex`` ------------------- This is a type for objects that support ``complex(x)``. This is a type for objects that support ``complex(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading @@ -321,7 +324,8 @@ This is a type for objects that support ``complex(x)``. ``SupportsFloat`` ----------------- This is a type for objects that support ``float(x)``. This is a type for objects that support ``float(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading @@ -330,7 +334,8 @@ This is a type for objects that support ``float(x)``. ``SupportsInt`` --------------- This is a type for objects that support ``int(x)``. This is a type for objects that support ``int(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading docs/source/command_line.rst +44 −15 Original line number Diff line number Diff line Loading @@ -19,21 +19,21 @@ flag (or its long form ``--help``):: [--warn-incomplete-stub] [--disallow-untyped-decorators] [--warn-redundant-casts] [--no-warn-no-return] [--warn-return-any] [--warn-unused-ignores] [--warn-unused-configs] [--show-error-context] [--no-implicit-optional] [-i] [--show-error-context] [--no-implicit-optional] [--no-incremental] [--quick-and-dirty] [--cache-dir DIR] [--cache-fine-grained] [--skip-version-check] [--strict-optional] [--strict-optional-whitelist [GLOB [GLOB ...]]] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] [--custom-typeshed-dir DIR] [--scripts-are-modules] [--config-file CONFIG_FILE] [--show-column-numbers] [--find-occurrences CLASS.MEMBER] [--strict] [--shadow-file SOURCE_FILE SHADOW_FILE] [--any-exprs-report DIR] [--cobertura-xml-report DIR] [--html-report DIR] [--linecount-report DIR] [--linecoverage-report DIR] [--memory-xml-report DIR] [--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE] [-c PROGRAM_TEXT] [-p PACKAGE] [--always-true NAME] [--always-false NAME] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] [--custom-typeshed-dir DIR] [--scripts-are-modules] [--config-file CONFIG_FILE] [--show-column-numbers] [--find-occurrences CLASS.MEMBER] [--strict] [--shadow-file SOURCE_FILE SHADOW_FILE] [--any-exprs-report DIR] [--cobertura-xml-report DIR] [--html-report DIR] [--linecount-report DIR] [--linecoverage-report DIR] [--memory-xml-report DIR] [--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files [files ...]] (etc., too long to show everything here) Loading Loading @@ -337,12 +337,15 @@ Here are some more useful flags: .. _incremental: - ``--incremental`` enables a module cache, using results from - Incremental mode 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 Incremental mode is the default and may be disabled with ``--no-incremental``. - ``--cache-dir DIR`` is a companion flag to incremental mode, 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 Loading @@ -363,17 +366,41 @@ Here are some more useful flags: updates the cache, but regular incremental mode ignores cache files written by quick mode. - ``--python-executable EXECUTABLE`` will have mypy collect type information from `PEP 561`_ compliant packages installed for the Python executable ``EXECUTABLE``. If not provided, mypy will use PEP 561 compliant packages installed for the Python executable running mypy. See :ref:`installed-packages` for more on making PEP 561 compliant packages. This flag will attempt to set ``--python-version`` if not already set. - ``--python-version X.Y`` will make mypy typecheck your code as if it were run under Python version X.Y. Without this option, mypy will default to using whatever version of Python is running mypy. Note that the ``-2`` and ``--py2`` flags are aliases for ``--python-version 2.7``. See :ref:`version_and_platform_checks` for more about this feature. :ref:`version_and_platform_checks` for more about this feature. This flag will attempt to find a Python executable of the corresponding version to search for `PEP 561`_ compliant packages. If you'd like to disable this, see ``--no-site-packages`` below. - ``--no-site-packages`` will disable searching for `PEP 561`_ compliant packages. This will also disable searching for a usable Python executable. Use this flag if mypy cannot find a Python executable for the version of Python being checked, and you don't need to use PEP 561 typed packages. Otherwise, use ``--python-executable``. - ``--platform PLATFORM`` will make mypy typecheck your code as if it were run under the the given operating system. Without this option, mypy will default to using whatever operating system you are currently using. See :ref:`version_and_platform_checks` for more about this feature. .. _always-true: - ``--always-true NAME`` will treat all variables named ``NAME`` as compile-time constants that are always true. May be repeated. - ``--always-false NAME`` will treat all variables named ``NAME`` as compile-time constants that are always false. May be repeated. - ``--show-column-numbers`` will add column offsets to error messages, for example, the following indicates an error in line 12, column 9 (note that column offsets are 0-based): Loading Loading @@ -450,6 +477,8 @@ For the remaining flags you can read the full ``mypy -h`` output. Command line flags are liable to change between releases. .. _PEP 561: https://www.python.org/dev/peps/pep-0561/ .. _integrating-mypy: Integrating mypy into another Python application Loading docs/source/common_issues.rst +12 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,18 @@ flagged as an error. clarity about the latter use ``--follow-imports=error``. You can read up about these and other useful flags in :ref:`command-line`. - **A function annotated as returning a non-optional type returns ``None`` and mypy doesn't complain**. .. code-block:: python def foo() -> str: return None # No error! By default, the ``None`` value is considered compatible with everything. See :ref:`optional` for details on strict optional checking, which allows mypy to check ``None`` values precisely, and will soon become default. .. _silencing_checker: Spurious errors and locally silencing the checker Loading Loading
PKG-INFO +1 −1 Original line number Diff line number Diff line Metadata-Version: 2.1 Name: mypy Version: 0.580 Version: 0.590 Summary: Optional static typing for Python Home-page: http://www.mypy-lang.org/ Author: Jukka Lehtosalo Loading
docs/source/cheat_sheet_py3.rst +39 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,45 @@ Python 3 introduces an annotation syntax for function declarations in `PEP 3107 ... Coroutines and asyncio ********************** See :ref:`async-and-await` for the full detail on typing coroutines and asynchronous code. .. code-block:: python import asyncio from typing import Generator, Any # A generator-based coroutine created with @asyncio.coroutine should have a # return type of Generator[Any, None, T], where T is the type it returns. @asyncio.coroutine def countdown34(tag: str, count: int) -> Generator[Any, None, str]: while count > 0: print('T-minus {} ({})'.format(count, tag)) yield from asyncio.sleep(0.1) count -= 1 return "Blastoff!" # mypy currently does not support converting functions into generator-based # coroutines in Python 3.4, so you need to add a 'yield' to make it # typecheck. @asyncio.coroutine def async1(obj: object) -> Generator[None, None, str]: if False: yield return "placeholder" # A Python 3.5+ coroutine is typed like a normal function. async def countdown35(tag: str, count: int) -> str: while count > 0: print('T-minus {} ({})'.format(count, tag)) await asyncio.sleep(0.1) count -= 1 return "Blastoff!" async def async2(obj: object) -> str: return "placeholder" When you're puzzled or when things are complicated ************************************************** Loading
docs/source/class_basics.rst +8 −3 Original line number Diff line number Diff line Loading @@ -309,10 +309,13 @@ This is a type for objects that support ``bytes(x)``. def __bytes__(self) -> bytes .. _supports-int-etc: ``SupportsComplex`` ------------------- This is a type for objects that support ``complex(x)``. This is a type for objects that support ``complex(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading @@ -321,7 +324,8 @@ This is a type for objects that support ``complex(x)``. ``SupportsFloat`` ----------------- This is a type for objects that support ``float(x)``. This is a type for objects that support ``float(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading @@ -330,7 +334,8 @@ This is a type for objects that support ``float(x)``. ``SupportsInt`` --------------- This is a type for objects that support ``int(x)``. This is a type for objects that support ``int(x)``. Note that no arithmetic operations are supported. .. code-block:: python Loading
docs/source/command_line.rst +44 −15 Original line number Diff line number Diff line Loading @@ -19,21 +19,21 @@ flag (or its long form ``--help``):: [--warn-incomplete-stub] [--disallow-untyped-decorators] [--warn-redundant-casts] [--no-warn-no-return] [--warn-return-any] [--warn-unused-ignores] [--warn-unused-configs] [--show-error-context] [--no-implicit-optional] [-i] [--show-error-context] [--no-implicit-optional] [--no-incremental] [--quick-and-dirty] [--cache-dir DIR] [--cache-fine-grained] [--skip-version-check] [--strict-optional] [--strict-optional-whitelist [GLOB [GLOB ...]]] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] [--custom-typeshed-dir DIR] [--scripts-are-modules] [--config-file CONFIG_FILE] [--show-column-numbers] [--find-occurrences CLASS.MEMBER] [--strict] [--shadow-file SOURCE_FILE SHADOW_FILE] [--any-exprs-report DIR] [--cobertura-xml-report DIR] [--html-report DIR] [--linecount-report DIR] [--linecoverage-report DIR] [--memory-xml-report DIR] [--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE] [-c PROGRAM_TEXT] [-p PACKAGE] [--always-true NAME] [--always-false NAME] [--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats] [--inferstats] [--custom-typing MODULE] [--custom-typeshed-dir DIR] [--scripts-are-modules] [--config-file CONFIG_FILE] [--show-column-numbers] [--find-occurrences CLASS.MEMBER] [--strict] [--shadow-file SOURCE_FILE SHADOW_FILE] [--any-exprs-report DIR] [--cobertura-xml-report DIR] [--html-report DIR] [--linecount-report DIR] [--linecoverage-report DIR] [--memory-xml-report DIR] [--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files [files ...]] (etc., too long to show everything here) Loading Loading @@ -337,12 +337,15 @@ Here are some more useful flags: .. _incremental: - ``--incremental`` enables a module cache, using results from - Incremental mode 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 Incremental mode is the default and may be disabled with ``--no-incremental``. - ``--cache-dir DIR`` is a companion flag to incremental mode, 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 Loading @@ -363,17 +366,41 @@ Here are some more useful flags: updates the cache, but regular incremental mode ignores cache files written by quick mode. - ``--python-executable EXECUTABLE`` will have mypy collect type information from `PEP 561`_ compliant packages installed for the Python executable ``EXECUTABLE``. If not provided, mypy will use PEP 561 compliant packages installed for the Python executable running mypy. See :ref:`installed-packages` for more on making PEP 561 compliant packages. This flag will attempt to set ``--python-version`` if not already set. - ``--python-version X.Y`` will make mypy typecheck your code as if it were run under Python version X.Y. Without this option, mypy will default to using whatever version of Python is running mypy. Note that the ``-2`` and ``--py2`` flags are aliases for ``--python-version 2.7``. See :ref:`version_and_platform_checks` for more about this feature. :ref:`version_and_platform_checks` for more about this feature. This flag will attempt to find a Python executable of the corresponding version to search for `PEP 561`_ compliant packages. If you'd like to disable this, see ``--no-site-packages`` below. - ``--no-site-packages`` will disable searching for `PEP 561`_ compliant packages. This will also disable searching for a usable Python executable. Use this flag if mypy cannot find a Python executable for the version of Python being checked, and you don't need to use PEP 561 typed packages. Otherwise, use ``--python-executable``. - ``--platform PLATFORM`` will make mypy typecheck your code as if it were run under the the given operating system. Without this option, mypy will default to using whatever operating system you are currently using. See :ref:`version_and_platform_checks` for more about this feature. .. _always-true: - ``--always-true NAME`` will treat all variables named ``NAME`` as compile-time constants that are always true. May be repeated. - ``--always-false NAME`` will treat all variables named ``NAME`` as compile-time constants that are always false. May be repeated. - ``--show-column-numbers`` will add column offsets to error messages, for example, the following indicates an error in line 12, column 9 (note that column offsets are 0-based): Loading Loading @@ -450,6 +477,8 @@ For the remaining flags you can read the full ``mypy -h`` output. Command line flags are liable to change between releases. .. _PEP 561: https://www.python.org/dev/peps/pep-0561/ .. _integrating-mypy: Integrating mypy into another Python application Loading
docs/source/common_issues.rst +12 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,18 @@ flagged as an error. clarity about the latter use ``--follow-imports=error``. You can read up about these and other useful flags in :ref:`command-line`. - **A function annotated as returning a non-optional type returns ``None`` and mypy doesn't complain**. .. code-block:: python def foo() -> str: return None # No error! By default, the ``None`` value is considered compatible with everything. See :ref:`optional` for details on strict optional checking, which allows mypy to check ``None`` values precisely, and will soon become default. .. _silencing_checker: Spurious errors and locally silencing the checker Loading