flake8-mypy


Nameflake8-mypy JSON
Version 17.8.0 PyPI version JSON
download
home_pagehttps://github.com/ambv/flake8-mypy
SummaryA plugin for flake8 integrating mypy.
upload_time2017-08-31 23:17:01
maintainer
docs_urlNone
authorŁukasz Langa
requires_python
licenseMIT
keywords flake8 mypy bugs linter qa typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            flake8-mypy
===========

|Build Status|

A plugin for `Flake8 <http://flake8.pycqa.org/>`__ integrating
`mypy <http://mypy-lang.org/>`__. The idea is to enable limited type
checking as a linter inside editors and other tools that already support
*Flake8* warning syntax and config.

NOTE: This plugin requires *mypy* >=0.500, as of Mar 1st no released
version satisfies this yet. You can use master in the mean time.

List of warnings
----------------

*flake8-mypy* reserves **T4** for all current and future codes, T being
the natural letter for typing-related errors. There are other plugins
greedily reserving the entire letter **T**. To this I say:
``¯\_(ツ)_/¯``.

**T400**: any typing note.

**T484**: any typing error (after PEP 484, geddit?).

**T498**: internal *mypy* error.

**T499**: internal *mypy* traceback, stderr output, or an unmatched
line.

I plan to support more fine-grained error codes for specific *mypy*
errors in the future.

Two levels of type checking
---------------------------

*mypy* shines when given a full program to analyze. You can then use
options like ``--follow-imports`` or ``--disallow-untyped-calls`` to
exercise the full transitive closure of your modules, catching errors
stemming from bad API usage or incompatible types. That being said,
those checks take time, and require access to the entire codebase. For
some tools, like an editor with an open file, or a code review tool,
achieving this is not trivial. This is where a more limited approach
inside a linter comes in.

*Flake8* operates on unrelated files, it doesn't perform full program
analysis. In other words, it doesn't follow imports. This is a curse and
a blessing. We cannot find complex problems and the number of warnings
we can safely show without risking false positives is lower. In return,
we can provide useful warnings with great performance, usable for
realtime editor integration.

As it turns out, in this mode of operation, *mypy* is still able to
provide useful information on the annotations within and at least usage
of stubbed standard library and third party libraries. However, for best
effects, you will want to use separate configuration for *mypy*'s
standalone mode and for usage as a *Flake8* plugin.

Configuration
-------------

Due to the reasoning above, by default *flake8-mypy* will operate with
options equivalent to the following:

.. code:: ini

    [mypy]
    # Specify the target platform details in config, so your developers are
    # free to run mypy on Windows, Linux, or macOS and get consistent
    # results.
    python_version=3.6
    platform=linux

    # flake8-mypy expects the two following for sensible formatting
    show_column_numbers=True
    show_error_context=False

    # do not follow imports (except for ones found in typeshed)
    follow_imports=skip

    # since we're ignoring imports, writing .mypy_cache doesn't make any sense
    cache_dir=/dev/null

    # suppress errors about unsatisfied imports
    ignore_missing_imports=True

    # allow untyped calls as a consequence of the options above
    disallow_untyped_calls=False

    # allow returning Any as a consequence of the options above
    warn_return_any=False

    # treat Optional per PEP 484
    strict_optional=True

    # ensure all execution paths are returning
    warn_no_return=True

    # lint-style cleanliness for typing needs to be disabled; returns more errors
    # than the full run.
    warn_redundant_casts=False
    warn_unused_ignores=False

    # The following are off by default since they're too noisy.
    # Flip them on if you feel adventurous.
    disallow_untyped_defs=False
    check_untyped_defs=False

If you disagree with the defaults above, you can specify your own *mypy*
configuration by providing the ``--mypy-config=`` command-line option to
*Flake8* (with the .flake8/setup.cfg equivalent being called
``mypy_config``). The value of that option should be a path to a
mypy.ini or setup.cfg compatible file. For full configuration syntax,
follow `mypy
documentation <http://mypy.readthedocs.io/en/latest/config_file.html>`__.

For the sake of simplicity and readability, the config you provide will
fully replace the one listed above. Values left out will be using
*mypy*'s own defaults.

Remember that for the best user experience, your linter integration mode
shouldn't generally display errors that a full run of *mypy* wouldn't.
This would be confusing.

Note: chaing the ``follow_imports`` option might have surprising
effects. If the file you're linting with Flake8 has other files around
it, then in "silent" or "normal" mode those files will be used to follow
imports. This includes imports from
`typeshed <https://github.com/python/typeshed/>`__.

Tests
-----

Just run:

::

    python setup.py test

OMG, this is Python 3 only!
---------------------------

Yes, so is *mypy*. Relax, you can run *Flake8* with all popular plugins
**as a tool** perfectly fine under Python 3.5+ even if you want to
analyze Python 2 code. This way you'll be able to parse all of the new
syntax supported on Python 3 but also *effectively all* the Python 2
syntax at the same time.

By making the code exclusively Python 3.5+, I'm able to focus on the
quality of the checks and re-use all the nice features of the new
releases (check out
`pathlib <docs.python.org/3/library/pathlib.html>`__) instead of wasting
cycles on Unicode compatibility, etc.

License
-------

MIT

Change Log
----------

17.8.0
~~~~~~

-  avoid raising errors in the default config which don't happen during
   a full run (disable warn\_unused\_ignores and warn\_redundant\_casts)

-  always run type checks from a temporary directory to avoid clashing
   with unrelated files in the same directory

17.3.3
~~~~~~

-  suppress *mypy* messages about relative imports

17.3.2
~~~~~~

-  bugfix: using *Flake8* with absolute paths now correctly matches
   *mypy* messages

-  bugfix: don't crash on relative imports in the form
   ``from . import X``

17.3.1
~~~~~~

-  switch ``follow_imports`` from "silent" to "skip" to avoid name
   clashing files being used to follow imports within
   `typeshed <https://github.com/python/typeshed/>`__

-  set MYPYPATH by default to give stubs from typeshed higher priority
   than local sources

17.3.0
~~~~~~

-  performance optimization: skip running *mypy* over files that contain
   no annotations or imports from ``typing``

-  bugfix: when running over an entire directory, T484 is now correctly
   used instead of T499

17.2.0
~~~~~~

-  first published version

-  date-versioned

Authors
-------

Glued together by `Łukasz Langa <mailto:lukasz@langa.pl>`__.

.. |Build Status| image:: https://travis-ci.org/ambv/flake8-mypy.svg?branch=master
   :target: https://travis-ci.org/ambv/flake8-mypy



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ambv/flake8-mypy",
    "name": "flake8-mypy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "flake8 mypy bugs linter qa typing",
    "author": "\u0141ukasz Langa",
    "author_email": "lukasz@langa.pl",
    "download_url": "https://files.pythonhosted.org/packages/97/9a/cddd1363d7314bb4eb452089c6fb3092ed9fda9f3350683d1978522a30ec/flake8-mypy-17.8.0.tar.gz",
    "platform": "",
    "description": "flake8-mypy\n===========\n\n|Build Status|\n\nA plugin for `Flake8 <http://flake8.pycqa.org/>`__ integrating\n`mypy <http://mypy-lang.org/>`__. The idea is to enable limited type\nchecking as a linter inside editors and other tools that already support\n*Flake8* warning syntax and config.\n\nNOTE: This plugin requires *mypy* >=0.500, as of Mar 1st no released\nversion satisfies this yet. You can use master in the mean time.\n\nList of warnings\n----------------\n\n*flake8-mypy* reserves **T4** for all current and future codes, T being\nthe natural letter for typing-related errors. There are other plugins\ngreedily reserving the entire letter **T**. To this I say:\n``\u00af\\_(\u30c4)_/\u00af``.\n\n**T400**: any typing note.\n\n**T484**: any typing error (after PEP 484, geddit?).\n\n**T498**: internal *mypy* error.\n\n**T499**: internal *mypy* traceback, stderr output, or an unmatched\nline.\n\nI plan to support more fine-grained error codes for specific *mypy*\nerrors in the future.\n\nTwo levels of type checking\n---------------------------\n\n*mypy* shines when given a full program to analyze. You can then use\noptions like ``--follow-imports`` or ``--disallow-untyped-calls`` to\nexercise the full transitive closure of your modules, catching errors\nstemming from bad API usage or incompatible types. That being said,\nthose checks take time, and require access to the entire codebase. For\nsome tools, like an editor with an open file, or a code review tool,\nachieving this is not trivial. This is where a more limited approach\ninside a linter comes in.\n\n*Flake8* operates on unrelated files, it doesn't perform full program\nanalysis. In other words, it doesn't follow imports. This is a curse and\na blessing. We cannot find complex problems and the number of warnings\nwe can safely show without risking false positives is lower. In return,\nwe can provide useful warnings with great performance, usable for\nrealtime editor integration.\n\nAs it turns out, in this mode of operation, *mypy* is still able to\nprovide useful information on the annotations within and at least usage\nof stubbed standard library and third party libraries. However, for best\neffects, you will want to use separate configuration for *mypy*'s\nstandalone mode and for usage as a *Flake8* plugin.\n\nConfiguration\n-------------\n\nDue to the reasoning above, by default *flake8-mypy* will operate with\noptions equivalent to the following:\n\n.. code:: ini\n\n    [mypy]\n    # Specify the target platform details in config, so your developers are\n    # free to run mypy on Windows, Linux, or macOS and get consistent\n    # results.\n    python_version=3.6\n    platform=linux\n\n    # flake8-mypy expects the two following for sensible formatting\n    show_column_numbers=True\n    show_error_context=False\n\n    # do not follow imports (except for ones found in typeshed)\n    follow_imports=skip\n\n    # since we're ignoring imports, writing .mypy_cache doesn't make any sense\n    cache_dir=/dev/null\n\n    # suppress errors about unsatisfied imports\n    ignore_missing_imports=True\n\n    # allow untyped calls as a consequence of the options above\n    disallow_untyped_calls=False\n\n    # allow returning Any as a consequence of the options above\n    warn_return_any=False\n\n    # treat Optional per PEP 484\n    strict_optional=True\n\n    # ensure all execution paths are returning\n    warn_no_return=True\n\n    # lint-style cleanliness for typing needs to be disabled; returns more errors\n    # than the full run.\n    warn_redundant_casts=False\n    warn_unused_ignores=False\n\n    # The following are off by default since they're too noisy.\n    # Flip them on if you feel adventurous.\n    disallow_untyped_defs=False\n    check_untyped_defs=False\n\nIf you disagree with the defaults above, you can specify your own *mypy*\nconfiguration by providing the ``--mypy-config=`` command-line option to\n*Flake8* (with the .flake8/setup.cfg equivalent being called\n``mypy_config``). The value of that option should be a path to a\nmypy.ini or setup.cfg compatible file. For full configuration syntax,\nfollow `mypy\ndocumentation <http://mypy.readthedocs.io/en/latest/config_file.html>`__.\n\nFor the sake of simplicity and readability, the config you provide will\nfully replace the one listed above. Values left out will be using\n*mypy*'s own defaults.\n\nRemember that for the best user experience, your linter integration mode\nshouldn't generally display errors that a full run of *mypy* wouldn't.\nThis would be confusing.\n\nNote: chaing the ``follow_imports`` option might have surprising\neffects. If the file you're linting with Flake8 has other files around\nit, then in \"silent\" or \"normal\" mode those files will be used to follow\nimports. This includes imports from\n`typeshed <https://github.com/python/typeshed/>`__.\n\nTests\n-----\n\nJust run:\n\n::\n\n    python setup.py test\n\nOMG, this is Python 3 only!\n---------------------------\n\nYes, so is *mypy*. Relax, you can run *Flake8* with all popular plugins\n**as a tool** perfectly fine under Python 3.5+ even if you want to\nanalyze Python\u00a02 code. This way you'll be able to parse all of the new\nsyntax supported on Python 3 but also *effectively all* the Python 2\nsyntax at the same time.\n\nBy making the code exclusively Python 3.5+, I'm able to focus on the\nquality of the checks and re-use all the nice features of the new\nreleases (check out\n`pathlib <docs.python.org/3/library/pathlib.html>`__) instead of wasting\ncycles on Unicode compatibility, etc.\n\nLicense\n-------\n\nMIT\n\nChange Log\n----------\n\n17.8.0\n~~~~~~\n\n-  avoid raising errors in the default config which don't happen during\n   a full run (disable warn\\_unused\\_ignores and warn\\_redundant\\_casts)\n\n-  always run type checks from a temporary directory to avoid clashing\n   with unrelated files in the same directory\n\n17.3.3\n~~~~~~\n\n-  suppress *mypy* messages about relative imports\n\n17.3.2\n~~~~~~\n\n-  bugfix: using *Flake8* with absolute paths now correctly matches\n   *mypy* messages\n\n-  bugfix: don't crash on relative imports in the form\n   ``from . import X``\n\n17.3.1\n~~~~~~\n\n-  switch ``follow_imports`` from \"silent\" to \"skip\" to avoid name\n   clashing files being used to follow imports within\n   `typeshed <https://github.com/python/typeshed/>`__\n\n-  set MYPYPATH by default to give stubs from typeshed higher priority\n   than local sources\n\n17.3.0\n~~~~~~\n\n-  performance optimization: skip running *mypy* over files that contain\n   no annotations or imports from ``typing``\n\n-  bugfix: when running over an entire directory, T484 is now correctly\n   used instead of T499\n\n17.2.0\n~~~~~~\n\n-  first published version\n\n-  date-versioned\n\nAuthors\n-------\n\nGlued together by `\u0141ukasz Langa <mailto:lukasz@langa.pl>`__.\n\n.. |Build Status| image:: https://travis-ci.org/ambv/flake8-mypy.svg?branch=master\n   :target: https://travis-ci.org/ambv/flake8-mypy\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A plugin for flake8 integrating mypy.",
    "version": "17.8.0",
    "split_keywords": [
        "flake8",
        "mypy",
        "bugs",
        "linter",
        "qa",
        "typing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a85db172de53870fc6fa2336a6f55dca0d67a70e2bf31218ed160aea3239e644",
                "md5": "033a9c997db8e7f3724b355ca262e2ba",
                "sha256": "cff009f4250e8391bf48990093cff85802778c345c8449d6498b62efefeebcbc"
            },
            "downloads": -1,
            "filename": "flake8_mypy-17.8.0-py35.py36-none-any.whl",
            "has_sig": true,
            "md5_digest": "033a9c997db8e7f3724b355ca262e2ba",
            "packagetype": "bdist_wheel",
            "python_version": "py35.py36",
            "requires_python": null,
            "size": 12664,
            "upload_time": "2017-08-31T23:16:58",
            "upload_time_iso_8601": "2017-08-31T23:16:58.624685Z",
            "url": "https://files.pythonhosted.org/packages/a8/5d/b172de53870fc6fa2336a6f55dca0d67a70e2bf31218ed160aea3239e644/flake8_mypy-17.8.0-py35.py36-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "979acddd1363d7314bb4eb452089c6fb3092ed9fda9f3350683d1978522a30ec",
                "md5": "b45a6b182c89d3bc0a8e96881c9d6b6d",
                "sha256": "47120db63aff631ee1f84bac6fe8e64731dc66da3efc1c51f85e15ade4a3ba18"
            },
            "downloads": -1,
            "filename": "flake8-mypy-17.8.0.tar.gz",
            "has_sig": true,
            "md5_digest": "b45a6b182c89d3bc0a8e96881c9d6b6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10994,
            "upload_time": "2017-08-31T23:17:01",
            "upload_time_iso_8601": "2017-08-31T23:17:01.140674Z",
            "url": "https://files.pythonhosted.org/packages/97/9a/cddd1363d7314bb4eb452089c6fb3092ed9fda9f3350683d1978522a30ec/flake8-mypy-17.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2017-08-31 23:17:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ambv",
    "github_project": "flake8-mypy",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flake8-mypy"
}
        
Elapsed time: 0.04123s