diff --git a/gokart/mypy.py b/gokart/mypy.py index 93a3067e..46f67a1c 100644 --- a/gokart/mypy.py +++ b/gokart/mypy.py @@ -97,8 +97,13 @@ def _task_on_kart_parameter_field_callback(self, ctx: FunctionContext) -> Type: foo: int = luigi.IntParameter() ``` """ + try: + default_idx = ctx.callee_arg_names.index('default') + # if no `default` argument is found, return AnyType with unannotated type. + except ValueError: + return AnyType(TypeOfAny.unannotated) - default_args = ctx.args[0] + default_args = ctx.args[default_idx] if default_args: default_type = ctx.arg_types[0][0] diff --git a/test/test_mypy.py b/test/test_mypy.py index 7bd0d4a8..545fcdde 100644 --- a/test/test_mypy.py +++ b/test/test_mypy.py @@ -12,6 +12,7 @@ def test_plugin_no_issue(self): import luigi from luigi import Parameter import gokart +import datetime class MyTask(gokart.TaskOnKart): @@ -20,6 +21,9 @@ class MyTask(gokart.TaskOnKart): bar: str = luigi.Parameter() # type: ignore baz: bool = gokart.ExplicitBoolParameter() qux: str = Parameter() + # https://github.com/m3dev/gokart/issues/395 + datetime: datetime.datetime = luigi.DateMinuteParameter(interval=10, default=datetime.datetime(2021, 1, 1)) + # TaskOnKart parameters: