-
Notifications
You must be signed in to change notification settings - Fork 124
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
bettet document how ‘self’ argument is handled #128
Comments
Hey @notestaff the implementation for args introspection is here.
Python will likely throw an error if you tried to do this. But i'm not sure exactly what you mean; provide an example if you want.
No, afaik this should work fine. I do agree the docs could be better. |
Yeah afaik: class doggy:
def bark();
park
doggy().bark() gives:
So not sure what you mean regarding the no |
In https://pluggy.readthedocs.io/en/latest/#call-time-order , SomeOtherPlugin.setup_project() takes no self, and is not marked with staticmethod. |
@notestaff that's a bug in the docs, opened #129 with a fix. Is that enough to close this issue? |
@notestaff yeah definitely just a typo. That code couldn't run in Python as demonstrated above :) |
maybe also copy the info about self from https://github.com/pytest-dev/pluggy/blob/master/pluggy/hooks.py#L109 to the main docs? Normally hookimpls can't have args that the hookspec doesn't, but 'self' is an exception to that, correct? |
@nicoddemus mind adding that little extra docs in your PR? |
i.e. whenever a hookimpl is called, pass the classit was originally discovered on to it when running it? I want to store some static class variables on the classes that are used to namespace my hookimpl, and I'd love for the hook funcs to be able to access their respective class attrs, as it would let you do simple (static/import-time) inheritance e.g.:
from pathlib import Path
from my_plugin_system import hookimpl
class DefaultCSSPlugin:
css_file: Path = 'some/path/to/default.css'
@hookimpl
@classmethod
def get_page_css(cls, page) -> str:
return Path(cls.css_file).read_text()
class LightModePlugin(DefaultCSSPlugin):
css_file = 'some/path/to/lightmode.css'
class DarkModePlugin(DefaultCSSPlugin):
css_file = 'some/path/to/darkmode.css' Example use: from .css_plugins import DefaultCSSPlugin, LightModePlugin, DarkModePlugin
pm.register(DefaultCSSPlugin)
pm.register(LightModePlugin)
pm.register(DarkModePlugin)
# this should register 3 implementations of get_page_css |
@pirate your example needs a explanation, it's unclear what you want to happen |
Ah sorry this was a red-herring, the issue I was encountering was actually caused by this: #536 (the plugin being a pydantic object broke plugin registration) Pluggy already preserves the |
It is optional, right? When registering a class with hook impls, the methods can omit the ‘self’ argument and not be @staticmethod , and things will work; in fact, decorating with @staticmethod might cause problems. Correct? Would help to clarify the docs.
The text was updated successfully, but these errors were encountered: