Skip to content

Commit

Permalink
docs: add docs for mypy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hiro-o918 committed Sep 20, 2024
1 parent 9a51f22 commit 41aae36
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:

- python-version: 3.9
tox-env: flake8
- python-version: 3.9
- python-version: 3.10
tox-env: docs

steps:
Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def _warn_node(self, msg, node, *args, **kwargs):
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False

autodoc_mock_imports = ["mypy"]

# Some regression introduced
# https://github.com/sphinx-doc/sphinx/issues/2330
# https://github.com/spotify/luigi/pull/1555
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Table of Contents
configuration.rst
logging.rst
design_and_limitations.rst
mypy.rst

API Reference
-------------
Expand Down
42 changes: 42 additions & 0 deletions doc/mypy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Mypy plugin
--------------

Mypy plugin provides type checking for ``luigi.Task`` using Mypy.

Require Python 3.8 or later.

How to use
~~~~~~~~~~

Configure Mypy to use this plugin by adding the following to your ``mypy.ini`` file:

.. code:: ini
[mypy]
plugins = luigi.mypy
or by adding the following to your ``pyproject.toml`` file:

.. code:: toml
[tool.mypy]
plugins = ["luigi.mypy"]
Then, run Mypy as usual.

Examples
~~~~~~~~

For example the following code linted by Mypy:

.. code:: python
import luigi
class MyTask(luigi.Task):
foo: int = luigi.IntParameter()
bar: str = luigi.Parameter()
MyTask(foo=1, bar='2') # OK
MyTask(foo='1', bar='2') # Error: Argument 1 to "Foo" has incompatible type "str"; expected "int"
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ deps =
sqlalchemy
boto3
jinja2==3.0.3
Sphinx>=1.4.4,<1.5
Sphinx>=1.4.4,<2.0
sphinx_rtd_theme
azure-storage-blob<=12.20.0
prometheus-client==0.5.0
alabaster<0.7.13
mypy
commands =
# build API docs
sphinx-apidoc -o doc/api -T luigi --separate
Expand Down

0 comments on commit 41aae36

Please sign in to comment.