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

Only pass-through kwargs if super class can take them #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oeoeaio
Copy link

@oeoeaio oeoeaio commented Mar 3, 2022

Fix for #80

@@ -72,7 +72,7 @@ def define_initialize_with_splat(super_parameters)
else
super_kwargs = slice_kwargs.(kwargs, super_parameters)

if super_kwargs.any?
if super_kwargs.any? && super_parameters.keyword_names.any?
Copy link
Member

Choose a reason for hiding this comment

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

Does it allocate a new array every time when asking for keyword_names? If yes, then it would be good to memoize it

Copy link
Author

Choose a reason for hiding this comment

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

As I read it, keyword_names are already memoized.

expect(instance.one).to eq 1
expect(instance.two).to eq 2
expect(instance.three).to eq 3
end
Copy link
Member

Choose a reason for hiding this comment

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

What's the expected behavior when you actually pass in kwargs to the constructor?

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean what is the expected behaviour if the super_klass in this test accepts kwargs? I suspect that is probably still broken as it was before this change. It would be nice to get this working with kwargs too but I can't think of a good way to achieve that without checking every single argument the constructor accepts and attempting to match each one before calling super.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should raise an error when you include auto-injector module and the super constructor is not compatible. WDYT?

Copy link

Choose a reason for hiding this comment

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

I agree. Loud and noisy is good.

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

3 participants