Skip to content

Commit 92f6b0d

Browse files
hiro-o918Hironori Yamamoto
and
Hironori Yamamoto
authored
fix: handle default type for DateMinuteParameter (#396)
Co-authored-by: Hironori Yamamoto <[email protected]>
1 parent b115c18 commit 92f6b0d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

gokart/mypy.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ def _task_on_kart_parameter_field_callback(self, ctx: FunctionContext) -> Type:
9797
foo: int = luigi.IntParameter()
9898
```
9999
"""
100+
try:
101+
default_idx = ctx.callee_arg_names.index('default')
102+
# if no `default` argument is found, return AnyType with unannotated type.
103+
except ValueError:
104+
return AnyType(TypeOfAny.unannotated)
100105

101-
default_args = ctx.args[0]
106+
default_args = ctx.args[default_idx]
102107

103108
if default_args:
104109
default_type = ctx.arg_types[0][0]

test/test_mypy.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_plugin_no_issue(self):
1212
import luigi
1313
from luigi import Parameter
1414
import gokart
15+
import datetime
1516
1617
1718
class MyTask(gokart.TaskOnKart):
@@ -20,6 +21,9 @@ class MyTask(gokart.TaskOnKart):
2021
bar: str = luigi.Parameter() # type: ignore
2122
baz: bool = gokart.ExplicitBoolParameter()
2223
qux: str = Parameter()
24+
# https://github.com/m3dev/gokart/issues/395
25+
datetime: datetime.datetime = luigi.DateMinuteParameter(interval=10, default=datetime.datetime(2021, 1, 1))
26+
2327
2428
2529
# TaskOnKart parameters:

0 commit comments

Comments
 (0)