From 39c06ee0ad135c3d02e6e5d95c5316502f7f22c4 Mon Sep 17 00:00:00 2001 From: Hironori Yamamoto Date: Sat, 21 Sep 2024 01:27:01 +0900 Subject: [PATCH] docs: add docs for mypy plugin --- doc/mypy.rst | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 doc/mypy.rst diff --git a/doc/mypy.rst b/doc/mypy.rst new file mode 100644 index 0000000000..4e067526ef --- /dev/null +++ b/doc/mypy.rst @@ -0,0 +1,44 @@ +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='bar') + + Foo(foo=1, bar='2') # OK + Foo(foo='1', bar='2') # Error: Argument 1 to "Foo" has incompatible type "str"; expected "int"