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

Can't load instances which define hook specs #19

Closed
goodboy opened this issue Aug 27, 2016 · 0 comments
Closed

Can't load instances which define hook specs #19

goodboy opened this issue Aug 27, 2016 · 0 comments

Comments

@goodboy
Copy link
Contributor

goodboy commented Aug 27, 2016

You currently can't instantiate a class which defines hook specs prior to loading

import pluggy

hookspec = pluggy.HookspecMarker('example')

class SpecSpace(object):
    @hookspec
    def myhook(self, stuff):
        """My custom hook spec.
        """

pluggy.PluginManager('example').add_hookspecs(SpecSpace())

because pluggy.varnames() doesn't successfully detect and remove the self name.

I realize this is an odd usage (and implied to be illegal based on the argname to add_hookspecs()) but it is conceivable. A contrived example might be where a user wishes to define the spec and the default hook implementation using the same function:

import pluggy

hookspec = pluggy.HookspecMarker('example')
hookimpl = pluggy.HookimplMarker('example')

class SpecSpace(object):
    def __init__(self, arg):
        self.arg = arg 

    @hookimpl
    @hookspec
    def hook1(self, stuff):
        """My custom hook spec.
        """
        if self.arg = 'doggy' and stuff == 'blah':
             # do this one thing
        else:
            # do this other thing

ss = SpecSpace('blah')
pm = pluggy.PluginManager('example')
pm.add_hookspecs(ss)
pm.register(ss)

I guess it's kind of silly...

Either way the implementation of pluggy.varnames is quite outdated and should be changed to more properly levarage the inspect module. If we prefer to not ever allow instances then a more explicit error should be thrown in PluginManager.add_hookspecs()

@hpk42 hpk42 closed this as completed in 4776698 Nov 11, 2016
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

1 participant