-
Notifications
You must be signed in to change notification settings - Fork 60
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: infer type of parameter when user doesn't specify type #403
Conversation
c0de16d
to
6f48b39
Compare
6f48b39
to
1cab2c6
Compare
1cab2c6
to
96d4d8e
Compare
@@ -361,65 +360,115 @@ def _collect_parameter_args(self, expr: Expression) -> tuple[bool, dict[str, Exp | |||
return True, args | |||
return False, {} | |||
|
|||
def _infer_task_on_kart_attr_init_type(self, sym: SymbolTableNode, context: Context) -> Type | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just a memo for this change)
This function aims to infer type for pydantic field, which is not needed on gokart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Great changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks!
if parameter_name in ['luigi.parameter.Parameter', 'luigi.parameter.OptionalParameter']: | ||
underlying_type = self._api.named_type('builtins.str', []) | ||
elif parameter_name in ['luigi.parameter.IntParameter', 'luigi.parameter.OptionalIntParameter']: | ||
underlying_type = self._api.named_type('builtins.int', []) | ||
elif parameter_name in ['luigi.parameter.FloatParameter', 'luigi.parameter.OptionalFloatParameter']: | ||
underlying_type = self._api.named_type('builtins.float', []) | ||
elif parameter_name in ['luigi.parameter.BoolParameter', 'luigi.parameter.OptionalBoolParameter']: | ||
underlying_type = self._api.named_type('builtins.bool', []) | ||
elif parameter_name in ['luigi.parameter.DateParameter', 'luigi.parameter.MonthParameter', 'luigi.parameter.YearParameter']: | ||
underlying_type = self._api.named_type('datetime.date', []) | ||
elif parameter_name in ['luigi.parameter.DateHourParameter', 'luigi.parameter.DateMinuteParameter', 'luigi.parameter.DateSecondParameter']: | ||
underlying_type = self._api.named_type('datetime.datetime', []) | ||
elif parameter_name in ['luigi.parameter.TimeDeltaParameter']: | ||
underlying_type = self._api.named_type('datetime.timedelta', []) | ||
elif parameter_name in ['luigi.parameter.DictParameter', 'luigi.parameter.OptionalDictParameter']: | ||
underlying_type = self._api.named_type('builtins.dict', [AnyType(TypeOfAny.unannotated), AnyType(TypeOfAny.unannotated)]) | ||
elif parameter_name in ['luigi.parameter.ListParameter', 'luigi.parameter.OptionalListParameter']: | ||
underlying_type = self._api.named_type('builtins.tuple', [AnyType(TypeOfAny.unannotated)]) | ||
elif parameter_name in ['luigi.parameter.TupleParameter', 'luigi.parameter.OptionalTupleParameter']: | ||
underlying_type = self._api.named_type('builtins.tuple', [AnyType(TypeOfAny.unannotated)]) | ||
elif parameter_name in ['luigi.parameter.PathParameter', 'luigi.parameter.OptionalPathParameter']: | ||
underlying_type = self._api.named_type('pathlib.Path', []) | ||
elif parameter_name in ['gokart.parameter.TaskInstanceParameter']: | ||
underlying_type = self._api.named_type('gokart.task.TaskOnKart', [AnyType(TypeOfAny.unannotated)]) | ||
elif parameter_name in ['gokart.parameter.ListTaskInstanceParameter']: | ||
underlying_type = self._api.named_type('builtins.list', [self._api.named_type('gokart.task.TaskOnKart', [AnyType(TypeOfAny.unannotated)])]) | ||
elif parameter_name in ['gokart.parameter.ExplicitBoolParameter']: | ||
underlying_type = self._api.named_type('builtins.bool', []) | ||
elif parameter_name in ['luigi.parameter.NumericalParameter']: | ||
underlying_type = self._get_type_from_args(parameter, 'var_type') | ||
elif parameter_name in ['luigi.parameter.ChoiceParameter']: | ||
underlying_type = self._get_type_from_args(parameter, 'var_type') | ||
elif parameter_name in ['luigi.parameter.ChoiceListPareameter']: | ||
base_type = self._get_type_from_args(parameter, 'var_type') | ||
if base_type is not None: | ||
underlying_type = self._api.named_type('builtins.tuple', [base_type]) | ||
elif parameter_name in ['luigi.parameter.EnumParameter']: | ||
underlying_type = self._get_type_from_args(parameter, 'enum') | ||
elif parameter_name in ['luigi.parameter.EnumListParameter']: | ||
base_type = self._get_type_from_args(parameter, 'enum') | ||
if base_type is not None: | ||
underlying_type = self._api.named_type('builtins.tuple', [base_type]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memo: After Python 3.9 EOL, we can use match case
syntax.
Currently, we should write type hint for every parameters. This PR aims to infer type from Parameter names when user doesn't specify type.
Before
After