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

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

Open
dwt opened this issue Mar 19, 2012 · 2 comments

Comments

@dwt
Copy link

dwt commented Mar 19, 2012

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
Copy link
Author

dwt commented Mar 19, 2012

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).

@mcdonc
Copy link
Member

mcdonc commented Jul 14, 2014

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.

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

2 participants