Skip to content

Commit

Permalink
feat: make parameters argument optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hiro-o918 committed Jul 21, 2024
1 parent 96ea087 commit ded0be5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions gokart/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from mypy.expandtype import expand_type, expand_type_by_instance
from mypy.nodes import (
ARG_NAMED,
ARG_NAMED_OPT,
ARG_POS,
Argument,
Expand Down Expand Up @@ -99,10 +98,9 @@ def __init__(

def to_argument(self, current_info: TypeInfo, *, of: Literal['__init__',]) -> Argument:
if of == '__init__':
# All arguments to __init__ are keyword-only.
arg_kind = ARG_NAMED
if self.has_default:
arg_kind = ARG_NAMED_OPT
# All arguments to __init__ are keyword-only and optional
# This is because gokart can set parameters by configuration'
arg_kind = ARG_NAMED_OPT
return Argument(
variable=self.to_var(current_info),
type_annotation=self.expand_type(current_info),
Expand Down
3 changes: 1 addition & 2 deletions gokart/testing/check_if_run_with_empty_data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def _test_run_with_empty_data_frame(cmdline_args: List[str], test_run_params: te

def try_to_run_test_for_empty_data_frame(cmdline_args: List[str]):
with CmdlineParser.global_instance(cmdline_args):
# NOTE: parameters passed by command line cannot be linted by mypy.
test_run_params = test_run() # type: ignore
test_run_params = test_run()

if test_run_params.pandas:
cmdline_args = [a for a in cmdline_args if not a.startswith('--test-run-')]
Expand Down
3 changes: 1 addition & 2 deletions test/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ class MyTask(gokart.TaskOnKart):
test_file.write(test_code.encode('utf-8'))
test_file.flush()
result = api.run(['--config-file', str(PYPROJECT_TOML), test_file.name])
self.assertIn('error: Missing named argument "bar" for "MyTask" [call-arg]', result[0])
self.assertIn('error: Argument "foo" to "MyTask" has incompatible type "str"; expected "int" [arg-type]', result[0])
self.assertIn('Found 2 errors in 1 file (checked 1 source file)', result[0])
self.assertIn('Found 1 errors in 1 file (checked 1 source file)', result[0])

0 comments on commit ded0be5

Please sign in to comment.