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

Method annotations incorrectly decorate inherited consumer methods #27

Closed
prkumar opened this issue Nov 21, 2017 · 1 comment
Closed

Comments

@prkumar
Copy link
Owner

prkumar commented Nov 21, 2017

Precondition

Consider the following consumer class:

class GitHub(uplink.Consumer):

    @uplink.get("/users/{username}")
    def get_user(self, username):
        """Get a single user."""

Use any method annotation. For this example, I'll create a custom method annotation, PrintMethodName, that simply prints the name of the consumer method that it wraps:

from uplink import decorators

class PrintMethodName(decorators.MethodAnnotation):

    def modify_request_definition(self, method):
        print(method.__name__)

Steps to recreate

Create a subclass of GitHub and decorate it with the method annotation:

@PrintMethodName()
class GitHubSubclass(GitHub):
    pass

Expected

No output to stdout, since GitHubSubclass doesn't define any consumer methods.

Actual

The method annotation decorates get_user from the parent class, GitHub.

Output:

get_user
@prkumar
Copy link
Owner Author

prkumar commented Nov 21, 2017

The root cause here is that uplink.helpers.get_api_definitions returns all consumer methods available to the given class -- including those inherited through the class hierarchy. Any fix for this issue should include a unit test that verifies that MethodAnnotations strictly decorates consumer methods defined in the decorated consumer's body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant