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

Why pluggy ignore hookimpl kwargsnames? #522

Open
noklam opened this issue Aug 15, 2024 · 4 comments
Open

Why pluggy ignore hookimpl kwargsnames? #522

noklam opened this issue Aug 15, 2024 · 4 comments

Comments

@noklam
Copy link

noklam commented Aug 15, 2024

Description

I try to set default argument for a hook and find it does not work.

class SomeClass:
  @hookimpl
  def my_func(self, a=1):
     ...

It seems like if I use a kwargs, pluggy will ignore this argument and won't call it anymore. I can see that HookImpl stores both kwargsnames and argnames but only argnames are called. Is this intentional or bug? I try to search in the docs but couldn't find anything related.

Context

for hook_impl in reversed(hook_impls):
try:
args = [caller_kwargs[argname] for argname in hook_impl.argnames]

In docs, it said:

naming markers: HookSpecMarker and HookImplMarker must be initialized with the name of the host project (the name parameter in setup()) - so eggsample in our case.

But it never mentioned keywords arguments cannot be used.

p.s. I did a bit more digging, it seems that kwargnames is never used anywhere in the source code other than saving it as an attribute.

image
@RonnyPfannschmidt
Copy link
Member

Currently default args are ignored

The discussion on support for them for forward or backward compatibility has not yet yielded implementations

@noklam
Copy link
Author

noklam commented Aug 16, 2024

@RonnyPfannschmidt Where can I find the related discussion? If it's not going to be implemented soon, does it makes sense to document this behavior for the time being? It would be great to get a view from pluggy standpoint as our users thought this is a bug on our side. We can add a few sentences in our own docs, but it will be nicer to reference pluggy's doc directly.

Something like `keyword arguments is not supported yet" is good enough.

@astrojuanlu
Copy link

Duplicate of #442, and I guess longer conversation goes all the way back to #15

@nicoddemus
Copy link
Member

Something like `keyword arguments is not supported yet" is good enough.

I agree, documenting the current status would be good.

Also the original post is a bit confusing, because the example is using a default value but mentioning keyword arguments, which are separate topics.

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

No branches or pull requests

4 participants