pytest-dev / pluggy

A minimalist production ready plugin system
https://pluggy.readthedocs.io/en/latest/
MIT License
1.31k stars 126 forks source link

Why does the hook function not receive **kwargs arguments? #554

Closed smallpekky closed 1 week ago

smallpekky commented 1 week ago

This is my hookimpl code

python

class myPlugin1:
    @hookimpl
    def myTest_after(self, **kwargs):
        print("The kwargs: ", kwargs)

invoke

def myTest(self):
    print("My hook test!")
    pm.hook.myTest_after(args1="hello", args2="world")

Running result

D:\software\python_pycharm\python\python.exe D:/learning/testDevlopment/pytest-main/src/my_pkg/hook_test.py
My hook test!
The kwargs:  {}

Process finished with exit code 0
RonnyPfannschmidt commented 1 week ago

pluggy intentionally passes only named positional arguments unnamed kwargs are not supported

part of the reason is historic as extracting arguments as a tuple for function calling more than doubled performance in earlier python versions

also it prevents user errors

smallpekky commented 1 week ago

pluggy intentionally passes only named positional arguments unnamed kwargs are not supported

part of the reason is historic as extracting arguments as a tuple for function calling more than doubled performance in earlier python versions

also it prevents user errors

Oh, I see. Thank you for your answer