example of decorator typing (#24857)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
from collections.abc import Callable
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from hmac import new as hmac_new
|
from hmac import new as hmac_new
|
||||||
|
from typing import ParamSpec, TypeVar
|
||||||
|
|
||||||
|
P = ParamSpec("P")
|
||||||
|
R = TypeVar("R")
|
||||||
from flask import abort, request
|
from flask import abort, request
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
@@ -10,9 +14,9 @@ from extensions.ext_database import db
|
|||||||
from models.model import EndUser
|
from models.model import EndUser
|
||||||
|
|
||||||
|
|
||||||
def billing_inner_api_only(view):
|
def billing_inner_api_only(view: Callable[P, R]):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args: P.args, **kwargs: P.kwargs):
|
||||||
if not dify_config.INNER_API:
|
if not dify_config.INNER_API:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@@ -26,9 +30,9 @@ def billing_inner_api_only(view):
|
|||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
|
|
||||||
def enterprise_inner_api_only(view):
|
def enterprise_inner_api_only(view: Callable[P, R]):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args: P.args, **kwargs: P.kwargs):
|
||||||
if not dify_config.INNER_API:
|
if not dify_config.INNER_API:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@@ -78,9 +82,9 @@ def enterprise_inner_api_user_auth(view):
|
|||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
|
|
||||||
def plugin_inner_api_only(view):
|
def plugin_inner_api_only(view: Callable[P, R]):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args: P.args, **kwargs: P.kwargs):
|
||||||
if not dify_config.PLUGIN_DAEMON_KEY:
|
if not dify_config.PLUGIN_DAEMON_KEY:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user