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

@returns.* decorator doesn't override the return annotation #144

Closed
prkumar opened this issue Mar 2, 2019 · 0 comments · Fixed by #154
Closed

@returns.* decorator doesn't override the return annotation #144

prkumar opened this issue Mar 2, 2019 · 0 comments · Fixed by #154
Labels
Milestone

Comments

@prkumar
Copy link
Owner

prkumar commented Mar 2, 2019

Describe the bug
When decorating a consumer method with @returns and also including a return annotation, it seems that the return annotation is considered the converter type instead of the type given in the @returns decorator.

To Reproduce
Here's an example that reproduces the issue:

from collections import namedtuple
from marshmallow import Schema, fields, post_load
from typing import List
from uplink import get, post, json, retry, returns, Consumer, Path, Query, Body

Repo = namedtuple("Repo", field_names=["owner", "name"])


class RepoResource(Schema):
    """Schema for GitHub's repository resource."""
    full_name = fields.Str()

    @post_load
    def make_repo(self, data):
        """Decodes the repository resource into a Python object."""
        return Repo(*data["full_name"].split("/"))


class GitHub(Consumer):
    """A Python Client for the GitHub API"""

    @retry(max_attempts=3)
    @returns.json(List[RepoResource])
    @get("/users/{user}/repos", args={"user": Path, "sort_by": Query("sort")})
    def get_repos(self, user: str, sort_by: str = "created") -> List[Repo]:
        """Get user's public repositories"""

    @json
    @returns.json(RepoResource)
    @post("/user/repos", args={"repo": Body(RepoResource), "access_token": Query})
    def create_repo(self, repo: Repo, access_token: str) -> Repo:
        """Create a repository for the authenticated user."""


if __name__ == "__main__":
    github = GitHub(base_url="https://api.github.com/")
    print(github.get_repos("prkumar"))

Expected behavior
The expected behavior here is to

Additional context
It seems that annotating the consumer class with @returns.* also is effected, as expected. We need to make sure that the use case of @returns as the class decorator is also supported.

@prkumar prkumar modified the milestones: v0.8.0, v0.9.0 Mar 2, 2019
@prkumar prkumar pinned this issue Mar 2, 2019
@prkumar prkumar added the Bug label Mar 15, 2019
prkumar added a commit that referenced this issue Mar 28, 2019
@prkumar prkumar unpinned this issue Apr 30, 2019
@prkumar prkumar mentioned this issue Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant