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

Does not work if class based view is decorated. #55

Open
sonthonaxrk opened this issue Apr 24, 2020 · 0 comments
Open

Does not work if class based view is decorated. #55

sonthonaxrk opened this issue Apr 24, 2020 · 0 comments

Comments

@sonthonaxrk
Copy link

    closure_contents = (c.cell_contents for c in cast(Any, fun).__closure__)
    fun_closure = dict(zip(fun.__code__.co_freevars, closure_contents))
    try:
        class_kwargs = fun_closure['class_kwargs']
    except KeyError:
        # Most likely flask_restful resource, we'll see in a second
        flask_restful_api = fun_closure['self']
        # flask_restful wraps ResourceClass.as_view() result in its own wrapper
        # the as_view() result is available under 'resource' name in this closure
        fun = fun_closure['resource']
        fun_closure = {}
        class_kwargs = {}
        # if the lines above succeeded we're quite sure it's flask_restful resource

The argument fun is the view function. If it's decorated, the value of fun.code.co_freevars will be scoped to the decorator, and it won't include fun_closure['self']

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

1 participant