venusian icon indicating copy to clipboard operation
venusian copied to clipboard

Callback interface is missing the object, key/ name pair under which the decorated method was found

Open dwt opened this issue 13 years ago • 2 comments

This makes it impossible to distinguish between the decorated object being inserted into an object under two names like this:

@venusion_decorator
def decorated(): pass

class VenusianUser(object):
  foo = decorated
  bar = decorated

My workaround was to use categories and skip some reuse but it would have made my code much easier if I could have gotten the actual object instance and the key under which the decorated object was found on whatever it was found.

dwt avatar Mar 19 '12 06:03 dwt

I would like to add that in our API we now use venusian like this:



    def step_names_and_handlers_for_category_name(self, *category_names):
        handlers = []
        scanner = venusian.Scanner(handlers=handlers)
        if len(category_names) == 0:
            category_names = None
        class MockModule(object):
            # This seems to be the only way to force the scanner to scan 
            # the actual instance instead of the class
            game_run = self
            delegate = self.delegate
        scanner.scan(MockModule, categories=category_names)
        return handlers

To scan instances of classes and venusian callbacks like this:



        def callback(scanner, name, obj):
            bound_method = getattr(obj, wrapped.func_name)
            scanner.handlers.append(dict(step_name=step_name, handler=bound_method))            

        venusian.attach(wrapped, callback, category=category_name)

To get the real bound decorated methods, but it is all a bit fragile as we can't support methods under multiple names (as noted above).

dwt avatar Mar 19 '12 06:03 dwt

Oh my dear this issue is old. Sorry about that. If you have any context into this still, maybe you can propose a patch? I honestly don't know how to support this particular usage.

mcdonc avatar Jul 14 '14 03:07 mcdonc