Skip to content
Myr

Merge pull request #4477 from tusharsadhwani/decorator-types

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add better types for app decorators

authored by David Lord · committed by GitHub · parents 8122973, af34b8c · 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

1 file+13 added−8 removed

modified:src/flask/scaffold.py+13 added-8 removed
367 unmodified lines
368 raise ValueError("Resources can only be opened for reading.")369370 return open(os.path.join(self.root_path, resource), mode)371372 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.")380381 return self.route(rule, methods=[method], **options)382378 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"]``.385386 .. versionadded:: 2.0387 """388 return self._method_route("GET", rule, options)389385 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"]``.392393 .. versionadded:: 2.0394 """395 return self._method_route("POST", rule, options)396392 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"]``.399400 .. versionadded:: 2.0401 """402 return self._method_route("PUT", rule, options)403399 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"]``.406407 .. versionadded:: 2.0408 """409 return self._method_route("DELETE", rule, options)410406 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"]``.413414 .. versionadded:: 2.0415 """416 return self._method_route("PATCH", rule, options)417413 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 lines
438 :param options: Extra options passed to the439 :class:`~werkzeug.routing.Rule` object.440 """441437 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