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

Class-level decorators on Consumer classes do not apply to inherited methods #119

Closed
prkumar opened this issue Nov 15, 2018 · 1 comment
Closed

Comments

@prkumar
Copy link
Owner

prkumar commented Nov 15, 2018

Describe the bug
For consumer classes that inherit consumer methods (i.e., methods decorated with @uplink.get, @uplink.post, etc.) from one or more parent classes, uplink decorators such as@response_handler or @timeout are not applied to those inherited methods when these decorators are used as class-level decorators. In other words, these decorators are strictly applied to consumer methods that are directly defined on the decorated consumer class.

To Reproduce
Consider the following consumer class:

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

Create a subclass of GitHub and decorate it with any uplink decorator that should propagate to consumer methods when used as a class decorator. For this example, I apply a @response_handler that should make any consumer method return the integer 1, regardless of the actual response returned by the server:

@response_handler(lambda resp: 1)
class GitHubSubclass(GitHub):
    pass

Here’s a quick test that shows that the response handler is not applied to the inherited method (i.e., the assertion fails):

client = GitHubSubclass(...)
assert github.get_user(“prkumar”) == 1

Expected behavior
Applying a decorator to a Consumer class should propagate to ALL consumer methods available to that class, including inherited consumer methods.

Additional context
Prior to v0.3.0, the actual behavior reflected the expected behavior detailed above. However, as part of #27, we unnecessarily began restricting the application of class-level decorators to only those consumer methods defined directly on the decorated consumer class. Hence, a fix for this bug should effectively revert the changes made in #27. Notably, this means that the fix should make changes to the function uplink.helpers.get_api_definitions.

@prkumar prkumar added this to the v0.7.0 milestone Nov 15, 2018
@prkumar
Copy link
Owner Author

prkumar commented Nov 15, 2018

FYI: @liiight

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