Improve decorator typing (#4676)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add a missing setupmethod decorator * Improve the decorator typing This will allow type checkers to understand that the decorators return the same function signature as passed as an argument. This follows the guidelines from https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators. I've chosen to keep a TypeVar per module and usage as I think encouraged by PEP 695, which I hope is accepted as the syntax is much nicer.
authored by Phil Jones · committed by GitHub · parent d7482cd · Browse files · 6 files·+123 added−76 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+123 added−76 removed
- tests:+5 added−0 removed
- other:+118 added−76 removed
Provenance
- Commit
9b44bf2- Tree
d151286- Author
Phil Jones <philip.graham.jones@googlemail.com>- Committer
GitHub <noreply@github.com>- Parent
d7482cd
6 files changed+123 added−76 removed
modified:src/flask/app.py+24 added-13 removed
72 unmodified lines73 from .blueprints import Blueprint74 from .testing import FlaskClient75 from .testing import FlaskCliRunner76 77+T_before_first_request = t.TypeVar(78+ "T_before_first_request", bound=ft.BeforeFirstRequestCallable79+)80+T_shell_context_processor = t.TypeVar(81+ "T_shell_context_processor", bound=ft.ShellContextProcessorCallable82+)83+T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)84+T_template_filter = t.TypeVar("T_template_filter", bound=ft.TemplateFilterCallable)85+T_template_global = t.TypeVar("T_template_global", bound=ft.TemplateGlobalCallable)86+T_template_test = t.TypeVar("T_template_test", bound=ft.TemplateTestCallable)87+88 if sys.version_info >= (3, 8):89 iscoroutinefunction = inspect.iscoroutinefunction90 else:91 390 unmodified lines482 #: A list of shell context processor functions that should be run483 #: when a shell context is created.484 #:485 #: .. versionadded:: 0.11475- self.shell_context_processors: t.List[t.Callable[[], t.Dict[str, t.Any]]] = []486+ self.shell_context_processors: t.List[ft.ShellContextProcessorCallable] = []487 488 #: Maps registered blueprint names to blueprint objects. The489 #: dict retains the order the blueprints were registered in.490 #: Blueprints can be registered multiple times, this dict does594 unmodified lines1085 def add_url_rule(1086 self,1087 rule: str,1088 endpoint: t.Optional[str] = None,1078- view_func: t.Optional[ft.ViewCallable] = None,1089+ view_func: t.Optional[ft.RouteCallable] = None,1090 provide_automatic_options: t.Optional[bool] = None,1091 **options: t.Any,1092 ) -> None:1093 if endpoint is None:48 unmodified lines1142 1143 @setupmethod1144 def template_filter(1145 self, name: t.Optional[str] = None1135- ) -> t.Callable[[ft.TemplateFilterCallable], ft.TemplateFilterCallable]:1146+ ) -> t.Callable[[T_template_filter], T_template_filter]:1147 """A decorator that is used to register custom template filter.1148 You can specify a name for the filter, otherwise the function1149 name will be used. Example::1150 4 unmodified lines1155 :param name: the optional name of the filter, otherwise the1156 function name will be used.1157 """1158 1148- def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:1159+ def decorator(f: T_template_filter) -> T_template_filter:1160 self.add_template_filter(f, name=name)1161 return f1162 1163 return decorator12 unmodified lines1176 1177 @setupmethod1178 def template_test(1179 self, name: t.Optional[str] = None1169- ) -> t.Callable[[ft.TemplateTestCallable], ft.TemplateTestCallable]:1180+ ) -> t.Callable[[T_template_test], T_template_test]:1181 """A decorator that is used to register custom template test.1182 You can specify a name for the test, otherwise the function1183 name will be used. Example::1184 11 unmodified lines1196 :param name: the optional name of the test, otherwise the1197 function name will be used.1198 """1199 1189- def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:1200+ def decorator(f: T_template_test) -> T_template_test:1201 self.add_template_test(f, name=name)1202 return f1203 1204 return decorator14 unmodified lines1219 1220 @setupmethod1221 def template_global(1222 self, name: t.Optional[str] = None1212- ) -> t.Callable[[ft.TemplateGlobalCallable], ft.TemplateGlobalCallable]:1223+ ) -> t.Callable[[T_template_global], T_template_global]:1224 """A decorator that is used to register a custom template global function.1225 You can specify a name for the global function, otherwise the function1226 name will be used. Example::1227 6 unmodified lines1234 :param name: the optional name of the global function, otherwise the1235 function name will be used.1236 """1237 1227- def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:1238+ def decorator(f: T_template_global) -> T_template_global:1239 self.add_template_global(f, name=name)1240 return f1241 1242 return decorator12 unmodified lines1255 """1256 self.jinja_env.globals[name or f.__name__] = f1257 1258 @setupmethod1248- def before_first_request(1249- self, f: ft.BeforeFirstRequestCallable1250- ) -> ft.BeforeFirstRequestCallable:1259+ def before_first_request(self, f: T_before_first_request) -> T_before_first_request:1260 """Registers a function to be run before the first request to this1261 instance of the application.1262 1263 The function will be called without any arguments and its return17 unmodified lines1281 self.before_first_request_funcs.append(f)1282 return f1283 1284 @setupmethod1276- def teardown_appcontext(self, f: ft.TeardownCallable) -> ft.TeardownCallable:1285+ def teardown_appcontext(self, f: T_teardown) -> T_teardown:1286 """Registers a function to be called when the application context1287 ends. These functions are typically also called when the request1288 context is popped.1289 24 unmodified lines1314 self.teardown_appcontext_funcs.append(f)1315 return f1316 1317 @setupmethod1309- def shell_context_processor(self, f: t.Callable) -> t.Callable:1318+ def shell_context_processor(1319+ self, f: T_shell_context_processor1320+ ) -> T_shell_context_processor:1321 """Registers a shell context processor function.1322 1323 .. versionadded:: 0.111324 """997 unmodified linesmodified:src/flask/blueprints.py+38 added-22 removed
11 unmodified lines12 if t.TYPE_CHECKING: # pragma: no cover13 from .app import Flask14 15 DeferredSetupFunction = t.Callable[["BlueprintSetupState"], t.Callable]16+T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable)17+T_before_first_request = t.TypeVar(18+ "T_before_first_request", bound=ft.BeforeFirstRequestCallable19+)20+T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable)21+T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable)22+T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)23+T_template_context_processor = t.TypeVar(24+ "T_template_context_processor", bound=ft.TemplateContextProcessorCallable25+)26+T_template_filter = t.TypeVar("T_template_filter", bound=ft.TemplateFilterCallable)27+T_template_global = t.TypeVar("T_template_global", bound=ft.TemplateGlobalCallable)28+T_template_test = t.TypeVar("T_template_test", bound=ft.TemplateTestCallable)29+T_url_defaults = t.TypeVar("T_url_defaults", bound=ft.URLDefaultCallable)30+T_url_value_preprocessor = t.TypeVar(31+ "T_url_value_preprocessor", bound=ft.URLValuePreprocessorCallable32+)33 34 35 class BlueprintSetupState:36 """Temporary holder object for registering a blueprint with the215 unmodified lines252 def wrapper(state: BlueprintSetupState) -> None:253 if state.first_registration:254 func(state)255 239- return self.record(update_wrapper(wrapper, func))256+ self.record(update_wrapper(wrapper, func))257 258 def make_setup_state(259 self, app: "Flask", options: dict, first_registration: bool = False260 ) -> BlueprintSetupState:147 unmodified lines408 def add_url_rule(409 self,410 rule: str,411 endpoint: t.Optional[str] = None,395- view_func: t.Optional[ft.ViewCallable] = None,412+ view_func: t.Optional[ft.RouteCallable] = None,413 provide_automatic_options: t.Optional[bool] = None,414 **options: t.Any,415 ) -> None:416 """Like :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for17 unmodified lines434 435 @setupmethod436 def app_template_filter(437 self, name: t.Optional[str] = None421- ) -> t.Callable[[ft.TemplateFilterCallable], ft.TemplateFilterCallable]:438+ ) -> t.Callable[[T_template_filter], T_template_filter]:439 """Register a custom template filter, available application wide. Like440 :meth:`Flask.template_filter` but for a blueprint.441 442 :param name: the optional name of the filter, otherwise the443 function name will be used.444 """445 429- def decorator(f: ft.TemplateFilterCallable) -> ft.TemplateFilterCallable:446+ def decorator(f: T_template_filter) -> T_template_filter:447 self.add_app_template_filter(f, name=name)448 return f449 450 return decorator17 unmodified lines468 469 @setupmethod470 def app_template_test(471 self, name: t.Optional[str] = None455- ) -> t.Callable[[ft.TemplateTestCallable], ft.TemplateTestCallable]:472+ ) -> t.Callable[[T_template_test], T_template_test]:473 """Register a custom template test, available application wide. Like474 :meth:`Flask.template_test` but for a blueprint.475 476 .. versionadded:: 0.101 unmodified line478 :param name: the optional name of the test, otherwise the479 function name will be used.480 """481 465- def decorator(f: ft.TemplateTestCallable) -> ft.TemplateTestCallable:482+ def decorator(f: T_template_test) -> T_template_test:483 self.add_app_template_test(f, name=name)484 return f485 486 return decorator19 unmodified lines506 507 @setupmethod508 def app_template_global(509 self, name: t.Optional[str] = None493- ) -> t.Callable[[ft.TemplateGlobalCallable], ft.TemplateGlobalCallable]:510+ ) -> t.Callable[[T_template_global], T_template_global]:511 """Register a custom template global, available application wide. Like512 :meth:`Flask.template_global` but for a blueprint.513 514 .. versionadded:: 0.101 unmodified line516 :param name: the optional name of the global, otherwise the517 function name will be used.518 """519 503- def decorator(f: ft.TemplateGlobalCallable) -> ft.TemplateGlobalCallable:520+ def decorator(f: T_template_global) -> T_template_global:521 self.add_app_template_global(f, name=name)522 return f523 524 return decorator17 unmodified lines542 543 self.record_once(register_template)544 545 @setupmethod529- def before_app_request(530- self, f: ft.BeforeRequestCallable531- ) -> ft.BeforeRequestCallable:546+ def before_app_request(self, f: T_before_request) -> T_before_request:547 """Like :meth:`Flask.before_request`. Such a function is executed548 before each request, even if outside of a blueprint.549 """550 self.record_once(2 unmodified lines553 return f554 555 @setupmethod556 def before_app_first_request(542- self, f: ft.BeforeFirstRequestCallable543- ) -> ft.BeforeFirstRequestCallable:557+ self, f: T_before_first_request558+ ) -> T_before_first_request:559 """Like :meth:`Flask.before_first_request`. Such a function is560 executed before the first request to the application.561 562 .. deprecated:: 2.211 unmodified lines574 )575 self.record_once(lambda s: s.app.before_first_request_funcs.append(f))576 return f577 563- def after_app_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:578+ @setupmethod579+ def after_app_request(self, f: T_after_request) -> T_after_request:580 """Like :meth:`Flask.after_request` but for a blueprint. Such a function581 is executed after each request, even if outside of the blueprint.582 """583 self.record_once(1 unmodified line585 )586 return f587 588 @setupmethod573- def teardown_app_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:589+ def teardown_app_request(self, f: T_teardown) -> T_teardown:590 """Like :meth:`Flask.teardown_request` but for a blueprint. Such a591 function is executed when tearing down each request, even if outside of592 the blueprint.593 """3 unmodified lines597 return f598 599 @setupmethod600 def app_context_processor(585- self, f: ft.TemplateContextProcessorCallable586- ) -> ft.TemplateContextProcessorCallable:601+ self, f: T_template_context_processor602+ ) -> T_template_context_processor:603 """Like :meth:`Flask.context_processor` but for a blueprint. Such a604 function is executed each request, even if outside of the blueprint.605 """606 self.record_once(3 unmodified lines610 611 @setupmethod612 def app_errorhandler(613 self, code: t.Union[t.Type[Exception], int]598- ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]:614+ ) -> t.Callable[[T_error_handler], T_error_handler]:615 """Like :meth:`Flask.errorhandler` but for a blueprint. This616 handler is used for all requests, even if outside of the blueprint.617 """618 603- def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator:619+ def decorator(f: T_error_handler) -> T_error_handler:620 self.record_once(lambda s: s.app.errorhandler(code)(f))621 return f622 623 return decorator624 625 @setupmethod626 def app_url_value_preprocessor(611- self, f: ft.URLValuePreprocessorCallable612- ) -> ft.URLValuePreprocessorCallable:627+ self, f: T_url_value_preprocessor628+ ) -> T_url_value_preprocessor:629 """Same as :meth:`url_value_preprocessor` but application wide."""630 self.record_once(631 lambda s: s.app.url_value_preprocessors.setdefault(None, []).append(f)632 )633 return f634 635 @setupmethod620- def app_url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:636+ def app_url_defaults(self, f: T_url_defaults) -> T_url_defaults:637 """Same as :meth:`url_defaults` but application wide."""638 self.record_once(639 lambda s: s.app.url_default_functions.setdefault(None, []).append(f)640 )1 unmodified linemodified:src/flask/scaffold.py+35 added-33 removed
26 unmodified lines27 # a singleton sentinel value for parameter defaults28 _sentinel = object()29 30 F = t.TypeVar("F", bound=t.Callable[..., t.Any])31+T_after_request = t.TypeVar("T_after_request", bound=ft.AfterRequestCallable)32+T_before_request = t.TypeVar("T_before_request", bound=ft.BeforeRequestCallable)33+T_error_handler = t.TypeVar("T_error_handler", bound=ft.ErrorHandlerCallable)34+T_teardown = t.TypeVar("T_teardown", bound=ft.TeardownCallable)35+T_template_context_processor = t.TypeVar(36+ "T_template_context_processor", bound=ft.TemplateContextProcessorCallable37+)38+T_url_defaults = t.TypeVar("T_url_defaults", bound=ft.URLDefaultCallable)39+T_url_value_preprocessor = t.TypeVar(40+ "T_url_value_preprocessor", bound=ft.URLValuePreprocessorCallable41+)42+T_route = t.TypeVar("T_route", bound=ft.RouteCallable)43 44 45 def setupmethod(f: F) -> F:46 f_name = f.__name__316 unmodified lines363 self,364 method: str,365 rule: str,366 options: dict,355- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:367+ ) -> t.Callable[[T_route], T_route]:368 if "methods" in options:369 raise TypeError("Use the 'route' decorator to use the 'methods' argument.")370 371 return self.route(rule, methods=[method], **options)372 373 @setupmethod362- def get(363- self, rule: str, **options: t.Any364- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:374+ def get(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:375 """Shortcut for :meth:`route` with ``methods=["GET"]``.376 377 .. versionadded:: 2.0378 """379 return self._method_route("GET", rule, options)380 381 @setupmethod372- def post(373- self, rule: str, **options: t.Any374- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:382+ def post(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:383 """Shortcut for :meth:`route` with ``methods=["POST"]``.384 385 .. versionadded:: 2.0386 """387 return self._method_route("POST", rule, options)388 389 @setupmethod382- def put(383- self, rule: str, **options: t.Any384- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:390+ def put(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:391 """Shortcut for :meth:`route` with ``methods=["PUT"]``.392 393 .. versionadded:: 2.0394 """395 return self._method_route("PUT", rule, options)396 397 @setupmethod392- def delete(393- self, rule: str, **options: t.Any394- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:398+ def delete(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:399 """Shortcut for :meth:`route` with ``methods=["DELETE"]``.400 401 .. versionadded:: 2.0402 """403 return self._method_route("DELETE", rule, options)404 405 @setupmethod402- def patch(403- self, rule: str, **options: t.Any404- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:406+ def patch(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:407 """Shortcut for :meth:`route` with ``methods=["PATCH"]``.408 409 .. versionadded:: 2.0410 """411 return self._method_route("PATCH", rule, options)412 413 @setupmethod412- def route(413- self, rule: str, **options: t.Any414- ) -> t.Callable[[ft.RouteDecorator], ft.RouteDecorator]:414+ def route(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:415 """Decorate a view function to register it with the given URL416 rule and options. Calls :meth:`add_url_rule`, which has more417 details about the implementation.418 15 unmodified lines434 :param options: Extra options passed to the435 :class:`~werkzeug.routing.Rule` object.436 """437 438- def decorator(f: ft.RouteDecorator) -> ft.RouteDecorator:438+ def decorator(f: T_route) -> T_route:439 endpoint = options.pop("endpoint", None)440 self.add_url_rule(rule, endpoint, f, **options)441 return f442 3 unmodified lines446 def add_url_rule(447 self,448 rule: str,449 endpoint: t.Optional[str] = None,450- view_func: t.Optional[ft.ViewCallable] = None,450+ view_func: t.Optional[ft.RouteCallable] = None,451 provide_automatic_options: t.Optional[bool] = None,452 **options: t.Any,453 ) -> None:454 """Register a rule for routing incoming requests and building55 unmodified lines510 """511 raise NotImplementedError512 513 @setupmethod514- def endpoint(self, endpoint: str) -> t.Callable:514+ def endpoint(self, endpoint: str) -> t.Callable[[F], F]:515 """Decorate a view function to register it for the given516 endpoint. Used if a rule is added without a ``view_func`` with517 :meth:`add_url_rule`.518 8 unmodified lines527 :param endpoint: The endpoint name to associate with the view528 function.529 """530 531- def decorator(f):531+ def decorator(f: F) -> F:532 self.view_functions[endpoint] = f533 return f534 535 return decorator536 537 @setupmethod538- def before_request(self, f: ft.BeforeRequestCallable) -> ft.BeforeRequestCallable:538+ def before_request(self, f: T_before_request) -> T_before_request:539 """Register a function to run before each request.540 541 For example, this can be used to open a database connection, or542 to load the logged in user from the session.13 unmodified lines556 self.before_request_funcs.setdefault(None, []).append(f)557 return f558 559 @setupmethod560- def after_request(self, f: ft.AfterRequestCallable) -> ft.AfterRequestCallable:560+ def after_request(self, f: T_after_request) -> T_after_request:561 """Register a function to run after each request to this object.562 563 The function is called with the response object, and must return564 a response object. This allows the functions to modify or7 unmodified lines572 self.after_request_funcs.setdefault(None, []).append(f)573 return f574 575 @setupmethod576- def teardown_request(self, f: ft.TeardownCallable) -> ft.TeardownCallable:576+ def teardown_request(self, f: T_teardown) -> T_teardown:577 """Register a function to be run at the end of each request,578 regardless of whether there was an exception or not. These functions579 are executed when the request context is popped, even if not an580 actual request was performed.24 unmodified lines605 return f606 607 @setupmethod608 def context_processor(609- self, f: ft.TemplateContextProcessorCallable610- ) -> ft.TemplateContextProcessorCallable:609+ self,610+ f: T_template_context_processor,611+ ) -> T_template_context_processor:612 """Registers a template context processor function."""613 self.template_context_processors[None].append(f)614 return f615 616 @setupmethod617 def url_value_preprocessor(617- self, f: ft.URLValuePreprocessorCallable618- ) -> ft.URLValuePreprocessorCallable:618+ self,619+ f: T_url_value_preprocessor,620+ ) -> T_url_value_preprocessor:621 """Register a URL value preprocessor function for all view622 functions in the application. These functions will be called before the623 :meth:`before_request` functions.624 8 unmodified lines633 self.url_value_preprocessors[None].append(f)634 return f635 636 @setupmethod635- def url_defaults(self, f: ft.URLDefaultCallable) -> ft.URLDefaultCallable:637+ def url_defaults(self, f: T_url_defaults) -> T_url_defaults:638 """Callback function for URL defaults for all view functions of the639 application. It's called with the endpoint and values and should640 update the values passed in place.641 """2 unmodified lines644 645 @setupmethod646 def errorhandler(647 self, code_or_exception: t.Union[t.Type[Exception], int]646- ) -> t.Callable[[ft.ErrorHandlerDecorator], ft.ErrorHandlerDecorator]:648+ ) -> t.Callable[[T_error_handler], T_error_handler]:649 """Register a function to handle errors by code or exception class.650 651 A decorator that is used to register a function given an652 error code. Example::21 unmodified lines674 :param code_or_exception: the code as integer for the handler, or675 an arbitrary exception676 """677 676- def decorator(f: ft.ErrorHandlerDecorator) -> ft.ErrorHandlerDecorator:678+ def decorator(f: T_error_handler) -> T_error_handler:679 self.register_error_handler(code_or_exception, f)680 return f681 682 return decorator210 unmodified linesmodified:src/flask/typing.py+20 added-7 removed
40 unmodified lines41 # callback annotated with flask.Response fail type checking.42 ResponseClass = t.TypeVar("ResponseClass", bound="Response")43 44 AppOrBlueprintKey = t.Optional[str] # The App key is None, whereas blueprints are named45-AfterRequestCallable = t.Callable[[ResponseClass], ResponseClass]46-BeforeFirstRequestCallable = t.Callable[[], None]47-BeforeRequestCallable = t.Callable[[], t.Optional[ResponseReturnValue]]48-TeardownCallable = t.Callable[[t.Optional[BaseException]], None]45+AfterRequestCallable = t.Union[46+ t.Callable[[ResponseClass], ResponseClass],47+ t.Callable[[ResponseClass], t.Awaitable[ResponseClass]],48+]49+BeforeFirstRequestCallable = t.Union[50+ t.Callable[[], None], t.Callable[[], t.Awaitable[None]]51+]52+BeforeRequestCallable = t.Union[53+ t.Callable[[], t.Optional[ResponseReturnValue]],54+ t.Callable[[], t.Awaitable[t.Optional[ResponseReturnValue]]],55+]56+ShellContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]57+TeardownCallable = t.Union[58+ t.Callable[[t.Optional[BaseException]], None],59+ t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],60+]61 TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]62 TemplateFilterCallable = t.Callable[..., t.Any]63 TemplateGlobalCallable = t.Callable[..., t.Any]64 TemplateTestCallable = t.Callable[..., bool]6 unmodified lines71 # https://github.com/pallets/flask/issues/409572 # https://github.com/pallets/flask/issues/429573 # https://github.com/pallets/flask/issues/429774 ErrorHandlerCallable = t.Callable[[t.Any], ResponseReturnValue]63-ErrorHandlerDecorator = t.TypeVar("ErrorHandlerDecorator", bound=ErrorHandlerCallable)75 65-ViewCallable = t.Callable[..., ResponseReturnValue]66-RouteDecorator = t.TypeVar("RouteDecorator", bound=ViewCallable)76+RouteCallable = t.Union[77+ t.Callable[..., ResponseReturnValue],78+ t.Callable[..., t.Awaitable[ResponseReturnValue]],79+]modified:src/flask/views.py+1 added-1 removed
80 unmodified lines81 82 @classmethod83 def as_view(84 cls, name: str, *class_args: t.Any, **class_kwargs: t.Any85- ) -> ft.ViewCallable:85+ ) -> ft.RouteCallable:86 """Convert the class into a view function that can be registered87 for a route.88 89 By default, the generated view will create a new instance of the99 unmodified linesmodified:tests/typing/typing_route.py+5 added
82 unmodified lines83 def return_template_stream() -> t.Iterator[str]:84 return stream_template("index.html", name="Hello")85 86 87+@app.route("/async")88+async def async_route() -> str:89+ return "Hello"90+91+92 class RenderTemplateView(View):93 def __init__(self: RenderTemplateView, template_name: str) -> None:94 self.template_name = template_name95 8 unmodified lines