Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mypy plugin #384

Merged
merged 12 commits into from
Jul 21, 2024
42 changes: 42 additions & 0 deletions docs/mypy_plugin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[Experimental] Mypy plugin
===========================

Mypy plugin provides type checking for gokart tasks using Mypy.
This feature is experimental.

How to use
--------------

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

.. code:: ini

[mypy]
plugins = gokart.mypy:plugin

or by adding the following to your ``pyproject.toml`` file:

.. code:: toml

[tool.mypy]
plugins = ["gokart.mypy:plugin"]

Then, run Mypy as usual.

For example the following code linted by Mypy:

.. code:: python

import gokart
import luigi


class Foo(gokart.TaskOnKart):
# NOTE: must all the parameters be annotated
foo: int = luigi.IntParameter(default=1)
bar: str = luigi.Parameter()



Foo(foo=1, bar='2') # OK
Foo(foo='1') # NG because foo is not int and bar is missing
3 changes: 2 additions & 1 deletion gokart/gcs_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from typing import Optional

import luigi
import luigi.contrib.gcs
Expand All @@ -18,7 +19,7 @@ def get_gcs_client(self) -> luigi.contrib.gcs.GCSClient:
def _get_gcs_client(self) -> luigi.contrib.gcs.GCSClient:
return luigi.contrib.gcs.GCSClient(oauth_credentials=self._load_oauth_credentials())

def _load_oauth_credentials(self) -> Credentials:
def _load_oauth_credentials(self) -> Optional[Credentials]:
json_str = os.environ.get(self.gcs_credential_name)
if not json_str:
return None
Expand Down
Loading