Add better types for app decorators
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tushar Sadhwani · committed by Tushar Sadhwani · parent 8122973 · Browse files · 1 file·+13 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+13 added−8 removed
- other:+13 added−8 removed
Provenance
- Commit
af34b8c- Tree
08939b2- Author
Tushar Sadhwani <tushar.sadhwani000@gmail.com>- Committer
Tushar Sadhwani <tushar.sadhwani000@gmail.com>- Parent
8122973
1 file changed+13 added−8 removed
modified:src/flask/scaffold.py+13 added-8 removed
367 unmodified lines368 raise ValueError("Resources can only be opened for reading.")369 370 return open(os.path.join(self.root_path, resource), mode)371 372- def _method_route(self, method: str, rule: str, options: dict) -> t.Callable:372+ def _method_route(373+ self,374+ method: str,375+ rule: str,376+ options: dict,377+ ) -> t.Callable[[F], F]:378 if "methods" in options:379 raise TypeError("Use the 'route' decorator to use the 'methods' argument.")380 381 return self.route(rule, methods=[method], **options)382 378- def get(self, rule: str, **options: t.Any) -> t.Callable:383+ def get(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:384 """Shortcut for :meth:`route` with ``methods=["GET"]``.385 386 .. versionadded:: 2.0387 """388 return self._method_route("GET", rule, options)389 385- def post(self, rule: str, **options: t.Any) -> t.Callable:390+ def post(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:391 """Shortcut for :meth:`route` with ``methods=["POST"]``.392 393 .. versionadded:: 2.0394 """395 return self._method_route("POST", rule, options)396 392- def put(self, rule: str, **options: t.Any) -> t.Callable:397+ def put(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:398 """Shortcut for :meth:`route` with ``methods=["PUT"]``.399 400 .. versionadded:: 2.0401 """402 return self._method_route("PUT", rule, options)403 399- def delete(self, rule: str, **options: t.Any) -> t.Callable:404+ def delete(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:405 """Shortcut for :meth:`route` with ``methods=["DELETE"]``.406 407 .. versionadded:: 2.0408 """409 return self._method_route("DELETE", rule, options)410 406- def patch(self, rule: str, **options: t.Any) -> t.Callable:411+ def patch(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:412 """Shortcut for :meth:`route` with ``methods=["PATCH"]``.413 414 .. versionadded:: 2.0415 """416 return self._method_route("PATCH", rule, options)417 413- def route(self, rule: str, **options: t.Any) -> t.Callable:418+ def route(self, rule: str, **options: t.Any) -> t.Callable[[F], F]:419 """Decorate a view function to register it with the given URL420 rule and options. Calls :meth:`add_url_rule`, which has more421 details about the implementation.422 15 unmodified lines438 :param options: Extra options passed to the439 :class:`~werkzeug.routing.Rule` object.440 """441 437- def decorator(f: t.Callable) -> t.Callable:442+ def decorator(f: F) -> F:443 endpoint = options.pop("endpoint", None)444 self.add_url_rule(rule, endpoint, f, **options)445 return f446 434 unmodified lines