Skip to content

Commit

Permalink
fix: handle default type for DateMinuteParameter (#396)
Browse files Browse the repository at this point in the history
Co-authored-by: Hironori Yamamoto <[email protected]>
  • Loading branch information
hiro-o918 and Hironori Yamamoto authored Sep 19, 2024
1 parent b115c18 commit 92f6b0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gokart/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions test/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def test_plugin_no_issue(self):
import luigi
from luigi import Parameter
import gokart
import datetime
class MyTask(gokart.TaskOnKart):
Expand All @@ -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:
Expand Down

0 comments on commit 92f6b0d

Please sign in to comment.