-
Notifications
You must be signed in to change notification settings - Fork 139
Closed
Description
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()
Metadata
Metadata
Assignees
Labels
No labels