Skip to content
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

Feature/ Runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound #305

Merged
merged 13 commits into from
Mar 2, 2023

Conversation

ujiuji1259
Copy link
Contributor

@ujiuji1259 ujiuji1259 commented Feb 4, 2023

Issue: #268

I've implemented runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound.

@ganow I'd like to use this feature, so I've created a PR based on your idea. Thank you for your feature request and the concrete implementation idea!

@ujiuji1259 ujiuji1259 changed the title Feature/ Runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound Draft: Feature/ Runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound Feb 4, 2023
@ujiuji1259 ujiuji1259 changed the title Draft: Feature/ Runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound Feature/ Runtime validation of TaskInstanceParameter() and ListTaskInstanceParameter() by subclass bound Feb 4, 2023
@ganow
Copy link

ganow commented Feb 6, 2023

@mski-iksm Thank you for creating the PR!

I forgot to make a PR after making this issue.

@ujiuji1259
Copy link
Contributor Author

@mski-iksm @hirosassa @Hi-king please review!

Copy link
Collaborator

@hirosassa hirosassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

logger = getLogger(__name__)


class TaskInstanceParameter(luigi.Parameter):

def __init__(self, *args, **kwargs):
bound = kwargs.pop('bound', gokart.TaskOnKart)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean subtype bound, how about just use 'type' keyword? There might be both upper and lower for 'bound' keyword.

gokart/parameter.py Outdated Show resolved Hide resolved
gokart/parameter.py Outdated Show resolved Hide resolved
@ujiuji1259
Copy link
Contributor Author

Thank you for the reviews!

I found _warn_on_wrong_param_type, and think overriding _warn_on_wrong_param_type to raise unexpected param type is more suitable in this situation.

How about this implementation?

Sample

class TaskInstanceParameter(luigi.Parameter):
    ...

    def _warn_on_wrong_param_type(self, param_name, param_value):
        if self.__class__ != TaskInstanceParameter:
            return
        if not isinstance(param_value, self.expected_type):
            raise TypeError(f'{param_value} is not an instance of {self.expected_type}')

@ujiuji1259 ujiuji1259 closed this Feb 22, 2023
@ujiuji1259 ujiuji1259 reopened this Feb 22, 2023
@ujiuji1259
Copy link
Contributor Author

I've updated implementation to use _warn_on_wrong_param_type.

Could you review again? @mski-iksm @hirosassa @Hi-king

gokart/parameter.py Outdated Show resolved Hide resolved
gokart/parameter.py Outdated Show resolved Hide resolved
gokart/parameter.py Outdated Show resolved Hide resolved
Copy link
Member

@Hi-king Hi-king left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mski-iksm mski-iksm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ujiuji1259 LGTM!

@Hi-king
Copy link
Member

Hi-king commented Mar 2, 2023

@ganow Thx for suggesting nice feature for improving reliability :)

@ujiuji1259 Thank you for the reasonable implementation! 👍

@Hi-king Hi-king merged commit 2230028 into m3dev:master Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants