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

Allow the instance of ResourceProtector to be a decorator without an unnecessary call if we don't have any 'call' attribute, solution provided. #604

Open
danilovmy opened this issue Dec 15, 2023 · 0 comments

Comments

@danilovmy
Copy link

for example on this page of documentation we can see:

@app.route('/user')
@require_oauth()
def user_profile():
    user = current_token.user
    return jsonify(user)

# or with None

@app.route('/user')
@require_oauth(None)
def user_profile():
    user = current_token.user
    return jsonify(user)

If we speak about transparency in coding, @require_oauth() is not an obvious practice.
More often, you can encounter @require_oauth.
Organizing the decorator for both cases — calling with and without attributes — is easy:

    def __call__(self, *args, **kwargs):
        if args and callable(args[0]):
            return super().__call__()(*args, **kwargs)
        return super().__call__(*args, **kwargs)
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