Skip to content

[MRG] allow child classes to override parents' tags #14069

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

Closed
wants to merge 4 commits into from

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Jun 11, 2019

Fixes #14044

This PR relaxes the current constraint on the tags and implements the solution proposed in #14044 (comment)

That is:

  • any child is allowed to override its parent's tags
  • if D inherits from B and C, then B and C must agree on their tags (else there's no way to know the tags of D). This constraint is dismissed if D overrides the inconsistent tags.

waiting to see if CI goes green

more_tags = base_class._more_tags(self)

if '_more_tags' in self.__class__.__dict__:
# we cannot use getattr since it would resolve to the parent's
Copy link
Member

Choose a reason for hiding this comment

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

we could use getattr(type(self), '_more_tags'), right?

Copy link
Member Author

Choose a reason for hiding this comment

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

no I think it would also resolve to the parents'

@amueller
Copy link
Member

Do we really want to overwrite the python inheritance mechanism just so we don't have to fix the way we inherit from mixins?

return

for direct_parent_class in c.__bases__:
_resolve_tags(direct_parent_class)
Copy link
Member

Choose a reason for hiding this comment

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

can't you do get_tags maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I suppose there are other ways to wrap it up

@NicolasHug
Copy link
Member Author

Do we really want to overwrite the python inheritance mechanism just so we don't have to fix the way we inherit from mixins

No idea yet. I'm just opening this so we have a concrete implementation of what it could look like.

@NicolasHug NicolasHug changed the title [WIP] allow child classes to override parents' tags [MRG] allow child classes to override parents' tags Jun 11, 2019

# filter-out tags that will be overridden in child class
more_tags = {key: val for (key, val) in more_tags.items()
if key not in overridden_tags.keys()}
Copy link
Member

Choose a reason for hiding this comment

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

So if you don't do this does the consistency check fails?

Does that generalize to multiple inheritances: A (has some tags) > B (overwrite tags) > (overwrite tags) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need this because we allow tags that are overridden on the child class to be inconsistent in the parents classes

overridden_tags = {}

def _resolve_tags(c):
nonlocal collected_tags
Copy link
Member

Choose a reason for hiding this comment

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

can't you just pass collected_tags as a reference to _resolve_tags?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@rth
Copy link
Member

rth commented Jun 20, 2019

Do we really want to overwrite the python inheritance mechanism just so we don't have to fix the way we inherit from mixins?

It's a pretty impressive solution @NicolasHug , but I'm also not so convinced about reimplementing something that behaves like python inheritance but not quite. I think, just using python MRO and fixing the mixin ordering would be a simpler and easier to maintain approach in the long run.

@NicolasHug
Copy link
Member Author

Agreed, closing :) !

@NicolasHug NicolasHug closed this Jun 26, 2019
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.

Estimator tag overwriting and update in _get_tags
3 participants