Skip to content
Closed

AI junk #6110

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
["get", "post", "head", "options", "delete", "put", "trace", "patch"]
)


class View:
"""Subclass this class and override :meth:`dispatch_request` to
create a generic class-based view. Call :meth:`as_view` to create a
Expand Down Expand Up @@ -75,7 +74,7 @@ def dispatch_request(self, name):
#: .. versionadded:: 2.2
init_every_request: t.ClassVar[bool] = True

def dispatch_request(self) -> ft.ResponseReturnValue:
def dispatch_request(self, *args: t.Any, **kwargs: t.Any) -> ft.ResponseReturnValue:
"""The actual view function behavior. Subclasses must override
this and return a valid response. Any variables from the URL
rule are passed as keyword arguments.
Expand Down Expand Up @@ -103,17 +102,17 @@ def as_view(
"""
if cls.init_every_request:

def view(**kwargs: t.Any) -> ft.ResponseReturnValue:
def view(*args: t.Any, **kwargs: t.Any) -> ft.ResponseReturnValue:
self = view.view_class( # type: ignore[attr-defined]
*class_args, **class_kwargs
)
return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs) # type: ignore[no-any-return]

else:
self = cls(*class_args, **class_kwargs) # pyright: ignore

def view(**kwargs: t.Any) -> ft.ResponseReturnValue:
return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return]
def view(*args: t.Any, **kwargs: t.Any) -> ft.ResponseReturnValue:
return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs) # type: ignore[no-any-return]

if cls.decorators:
view.__name__ = name
Expand All @@ -134,7 +133,6 @@ def view(**kwargs: t.Any) -> ft.ResponseReturnValue:
view.provide_automatic_options = cls.provide_automatic_options # type: ignore
return view


class MethodView(View):
"""Dispatches request methods to the corresponding instance methods.
For example, if you implement a ``get`` method, it will be used to
Expand Down Expand Up @@ -179,7 +177,7 @@ def __init_subclass__(cls, **kwargs: t.Any) -> None:
if methods:
cls.methods = methods

def dispatch_request(self, **kwargs: t.Any) -> ft.ResponseReturnValue:
def dispatch_request(self, *args: t.Any, **kwargs: t.Any) -> ft.ResponseReturnValue:
meth = getattr(self, request.method.lower(), None)

# If the request method is HEAD and we don't have a handler for it
Expand All @@ -188,4 +186,4 @@ def dispatch_request(self, **kwargs: t.Any) -> ft.ResponseReturnValue:
meth = getattr(self, "get", None)

assert meth is not None, f"Unimplemented method {request.method!r}"
return current_app.ensure_sync(meth)(**kwargs) # type: ignore[no-any-return]
return current_app.ensure_sync(meth)(*args, **kwargs) # type: ignore[no-any-return]
Loading