refactor(api): enable reportUntypedFunctionDecorator in pyright config (#26412) (#35031)

This commit is contained in:
Ygor Leal 2026-04-13 05:28:23 +02:00 committed by GitHub
parent 596559efc9
commit b5259a3a85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 18 deletions

View File

@ -94,10 +94,9 @@ def get_user_tenant[**P, R](view_func: Callable[P, R]) -> Callable[P, R]:
def plugin_data[**P, R]( def plugin_data[**P, R](
view: Callable[P, R] | None = None,
*, *,
payload_type: type[BaseModel], payload_type: type[BaseModel],
) -> Callable[P, R] | Callable[[Callable[P, R]], Callable[P, R]]: ) -> Callable[[Callable[P, R]], Callable[P, R]]:
def decorator(view_func: Callable[P, R]) -> Callable[P, R]: def decorator(view_func: Callable[P, R]) -> Callable[P, R]:
@wraps(view_func) @wraps(view_func)
def decorated_view(*args: P.args, **kwargs: P.kwargs) -> R: def decorated_view(*args: P.args, **kwargs: P.kwargs) -> R:
@ -116,7 +115,4 @@ def plugin_data[**P, R](
return decorated_view return decorated_view
if view is None: return decorator
return decorator
else:
return decorator(view)

View File

@ -17,7 +17,6 @@ def http_status_message(code):
def register_external_error_handlers(api: Api): def register_external_error_handlers(api: Api):
@api.errorhandler(HTTPException)
def handle_http_exception(e: HTTPException): def handle_http_exception(e: HTTPException):
got_request_exception.send(current_app, exception=e) got_request_exception.send(current_app, exception=e)
@ -74,27 +73,18 @@ def register_external_error_handlers(api: Api):
headers["Set-Cookie"] = build_force_logout_cookie_headers() headers["Set-Cookie"] = build_force_logout_cookie_headers()
return data, status_code, headers return data, status_code, headers
_ = handle_http_exception
@api.errorhandler(ValueError)
def handle_value_error(e: ValueError): def handle_value_error(e: ValueError):
got_request_exception.send(current_app, exception=e) got_request_exception.send(current_app, exception=e)
status_code = 400 status_code = 400
data = {"code": "invalid_param", "message": str(e), "status": status_code} data = {"code": "invalid_param", "message": str(e), "status": status_code}
return data, status_code return data, status_code
_ = handle_value_error
@api.errorhandler(AppInvokeQuotaExceededError)
def handle_quota_exceeded(e: AppInvokeQuotaExceededError): def handle_quota_exceeded(e: AppInvokeQuotaExceededError):
got_request_exception.send(current_app, exception=e) got_request_exception.send(current_app, exception=e)
status_code = 429 status_code = 429
data = {"code": "too_many_requests", "message": str(e), "status": status_code} data = {"code": "too_many_requests", "message": str(e), "status": status_code}
return data, status_code return data, status_code
_ = handle_quota_exceeded
@api.errorhandler(Exception)
def handle_general_exception(e: Exception): def handle_general_exception(e: Exception):
got_request_exception.send(current_app, exception=e) got_request_exception.send(current_app, exception=e)
@ -113,7 +103,10 @@ def register_external_error_handlers(api: Api):
return data, status_code return data, status_code
_ = handle_general_exception api.errorhandler(HTTPException)(handle_http_exception)
api.errorhandler(ValueError)(handle_value_error)
api.errorhandler(AppInvokeQuotaExceededError)(handle_quota_exceeded)
api.errorhandler(Exception)(handle_general_exception)
class ExternalApi(Api): class ExternalApi(Api):

View File

@ -47,7 +47,6 @@
"reportMissingTypeArgument": "hint", "reportMissingTypeArgument": "hint",
"reportUnnecessaryComparison": "hint", "reportUnnecessaryComparison": "hint",
"reportUnnecessaryIsInstance": "hint", "reportUnnecessaryIsInstance": "hint",
"reportUntypedFunctionDecorator": "hint",
"reportUnnecessaryTypeIgnoreComment": "hint", "reportUnnecessaryTypeIgnoreComment": "hint",
"reportAttributeAccessIssue": "hint", "reportAttributeAccessIssue": "hint",
"pythonVersion": "3.12", "pythonVersion": "3.12",