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

WIP: Detect parameter collisions in the @inherits decorator. See #2566 for more details. #2565

Conversation

KenyaDonDraper
Copy link
Contributor

Detect parameter collisions while using the @inherits and the associated
@requires decorator. Collision detection for a particular parameter can
be opted out by adding it to the 'ignore_collisions=[]' list argument
of the decorator.

Detect parameter collisions while using the @inherits and the associated
@requires decorator. Collision detection for a particular parameter can
be opted out by adding it to the 'ignore_collisions=[]' list argument
of the decorator.
@KenyaDonDraper KenyaDonDraper changed the title Detect parameter collisions in the @inherits decorator. WIP: Detect parameter collisions in the @inherits decorator. Oct 31, 2018
@KenyaDonDraper KenyaDonDraper changed the title WIP: Detect parameter collisions in the @inherits decorator. WIP: Detect parameter collisions in the @inherits decorator - see #2566 Oct 31, 2018
@KenyaDonDraper KenyaDonDraper changed the title WIP: Detect parameter collisions in the @inherits decorator - see #2566 WIP: Detect parameter collisions in the @inherits decorator.see #2566 Oct 31, 2018
@KenyaDonDraper KenyaDonDraper changed the title WIP: Detect parameter collisions in the @inherits decorator.see #2566 WIP: Detect parameter collisions in the @inherits decorator. See #2566 for more details. Oct 31, 2018
Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR!

While i'm not a user of this feature, I'm happy to see improvements upon it and i'll continue to provide general code and luigi reviews.

I realize this is a WIP, but thought i'd go ahead and submit a quick, superficial review :)

super(inherits, self).__init__()
if not tasks_to_inherit:
raise TypeError("tasks_to_inherit cannot be empty")

self.tasks_to_inherit = tasks_to_inherit
self.ignore_collisions = ignore_collisions
Copy link
Collaborator

Choose a reason for hiding this comment

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

highly recommend

def __init__(self, *tasks_to_inherit, ignore_collisions=None):
    ...
    self.ignore_collisions = ignore_collisions or []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that was a bad practice. Assuming the mistake was using the mutable default argument, I actually prefer replacing the empty list with a tuple,

def __init__(self, *tasks_to_inherit, ignore_collisions=()):
    ...
    self.ignore_collisions = ignore_collisions

This way we remove the mutable default argument and at the same time allow the argument to communicate to a developer that the expected input is a sequence. The fewer lines the developer has to read before inferring the expected input the better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No complaint from me :)

luigi/util.py Outdated
self.check_for_parameter_collisions(task_that_inherits)

# Get all parameter objects from each of the underlying tasks and
# them to the inheriting task.
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe a typo... not sure what you are trying to say and them to the inheriting task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes typo, thanks. Was supposed to read: and add them to the inheriting task. Will make the change.

luigi/util.py Outdated
error_msg = (
"Parameter name collision detected in tasks_to_inherit. "
"Parameter '{param}' in '{task}' duplicates "
"parameter '{param}' in {another_task}. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

could probably be simplified to Parameter {param} in {task} is duplicated in {another_task}. No need to continually output the name of the parameter if there is a collision due to the names being the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Will make the change.

luigi/util.py Outdated

# Check that the parameters from an inherited task don't mask the
# parameters from another inherited task.
for task_to_inherit in self.tasks_to_inherit:
Copy link
Collaborator

Choose a reason for hiding this comment

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

As written, this loop is ran 3 times. 2 within this method and once afterward. Is there anyway to combine the looping of these tasks_to_inherit to avoid repetitive looping?

super(requires, self).__init__()
if not tasks_to_require:
raise TypeError("tasks_to_require cannot be empty")

self.tasks_to_require = tasks_to_require
self.ignore_collisions = ignore_collisions
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here as mentioned above

@stale
Copy link

stale bot commented Mar 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If closed, you may revisit when your time allows and reopen! Thank you for your contributions.

@stale stale bot added the wontfix label Mar 23, 2019
@TMaYaD
Copy link
Contributor

TMaYaD commented Apr 5, 2019

FWIW, we found the name inherits very confusing for new users. We renamed it to _include_params_from and enhanced it to customise the parameters: https://gist.github.com/TMaYaD/1c5e0898179699bdc1885ff05cbea552

Let me know if I should open a PR for it.

@stale stale bot removed the wontfix label Apr 5, 2019
@stale
Copy link

stale bot commented Aug 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If closed, you may revisit when your time allows and reopen! Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants