Skip to content

Commit

Permalink
Precision on DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Oct 12, 2022
1 parent 72ef4bb commit 51e22d6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 90 deletions.
63 changes: 0 additions & 63 deletions starlette/applications.py
Expand Up @@ -124,37 +124,17 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
scope["app"] = self
await self.middleware_stack(scope, receive, send)

# The following usages are now discouraged in favour of configuration
# during Starlette.__init__(...)
def on_event(self, event_type: str) -> typing.Callable: # pragma: nocover
warnings.warn(
"The `on_event` decorator is deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/events/#registering-events for recommended approach.", # noqa: E501
DeprecationWarning,
)

return self.router.on_event(event_type)

def mount(
self, path: str, app: ASGIApp, name: typing.Optional[str] = None
) -> None: # pragma: nocover
warnings.warn(
"The 'mount' method is now deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/routing/#submounting-routes for recommended approach.", # noqa: E501
DeprecationWarning,
)

self.router.mount(path, app=app, name=name)

def host(
self, host: str, app: ASGIApp, name: typing.Optional[str] = None
) -> None: # pragma: no cover
warnings.warn(
"The 'host' method is deprecated, and will be removed in version 1.0.0."
"Refer to https://www.starlette.io/routing/#host-based-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)

self.router.host(host, app=app, name=name)

def add_middleware(
Expand All @@ -173,22 +153,12 @@ def add_exception_handler(
exc_class_or_status_code: typing.Union[int, typing.Type[Exception]],
handler: typing.Callable,
) -> None: # pragma: no cover
warnings.warn(
"The `add_exception_handler` method is deprecated, and will be removed in version 1.0.0." # noqa: E501
"Refer to https://www.starlette.io/exceptions/ for the recommended approach.", # noqa: E501
DeprecationWarning,
)
self.exception_handlers[exc_class_or_status_code] = handler
self.middleware_stack = self.build_middleware_stack()

def add_event_handler(
self, event_type: str, func: typing.Callable
) -> None: # pragma: no cover
warnings.warn(
"The `add_event_handler` method is deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/events/#registering-events for recommended approach.", # noqa: E501
DeprecationWarning,
)
self.router.add_event_handler(event_type, func)

def add_route(
Expand All @@ -199,34 +169,18 @@ def add_route(
name: typing.Optional[str] = None,
include_in_schema: bool = True,
) -> None: # pragma: no cover
warnings.warn(
"The `add_route` method is deprecated, and will be removed in version 1.0.0." # noqa: E501
"Refer to https://www.starlette.io/routing/#http-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)
self.router.add_route(
path, route, methods=methods, name=name, include_in_schema=include_in_schema
)

def add_websocket_route(
self, path: str, route: typing.Callable, name: typing.Optional[str] = None
) -> None: # pragma: no cover
warnings.warn(
"The `add_websocket_route` method is deprecated, and will be removed in version 1.0.0. Refer to " # noqa: E501
"https://www.starlette.io/routing/#websocket-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)
self.router.add_websocket_route(path, route, name=name)

def exception_handler(
self, exc_class_or_status_code: typing.Union[int, typing.Type[Exception]]
) -> typing.Callable: # pragma: nocover
warnings.warn(
"The `exception_handler` decorator is deprecated, and will be removed in version 1.0.0." # noqa: E501
"Refer to https://www.starlette.io/exceptions/ for the recommended approach.", # noqa: E501
DeprecationWarning,
)

def decorator(func: typing.Callable) -> typing.Callable:
self.add_exception_handler(exc_class_or_status_code, func)
return func
Expand All @@ -240,12 +194,6 @@ def route(
name: typing.Optional[str] = None,
include_in_schema: bool = True,
) -> typing.Callable: # pragma: nocover
warnings.warn(
"The `route` decorator is deprecated, and will be removed in version 1.0.0."
"Refer to https://www.starlette.io/routing/#http-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)

def decorator(func: typing.Callable) -> typing.Callable:
self.router.add_route(
path,
Expand All @@ -261,24 +209,13 @@ def decorator(func: typing.Callable) -> typing.Callable:
def websocket_route(
self, path: str, name: typing.Optional[str] = None
) -> typing.Callable: # pragma: nocover
warnings.warn(
"The `websocket_route` decorator is deprecated, and will be removed in version 1.0.0. Refer to " # noqa: E501
"https://www.starlette.io/routing/#websocket-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)

def decorator(func: typing.Callable) -> typing.Callable:
self.router.add_websocket_route(path, func, name=name)
return func

return decorator

def middleware(self, middleware_type: str) -> typing.Callable: # pragma: nocover
warnings.warn(
"The `middleware` decorator is deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/middleware/#using-middleware for recommended approach.", # noqa: E501
DeprecationWarning,
)
assert (
middleware_type == "http"
), 'Currently only middleware("http") is supported.'
Expand Down
27 changes: 0 additions & 27 deletions starlette/routing.py
Expand Up @@ -737,27 +737,15 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
def __eq__(self, other: typing.Any) -> bool:
return isinstance(other, Router) and self.routes == other.routes

# The following usages are now discouraged in favour of configuration
#  during Router.__init__(...)
def mount(
self, path: str, app: ASGIApp, name: typing.Optional[str] = None
) -> None: # pragma: nocover
warnings.warn(
"The 'mount' method is now deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/routing/#submounting-routes for recommended approach.", # noqa: E501
DeprecationWarning,
)
route = Mount(path, app=app, name=name)
self.routes.append(route)

def host(
self, host: str, app: ASGIApp, name: typing.Optional[str] = None
) -> None: # pragma: no cover
warnings.warn(
"The 'host' method is deprecated, and will be removed in version 1.0.0."
"Refer to https://www.starlette.io/routing/#host-based-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)
route = Host(host, app=app, name=name)
self.routes.append(route)

Expand All @@ -769,11 +757,6 @@ def add_route(
name: typing.Optional[str] = None,
include_in_schema: bool = True,
) -> None: # pragma: nocover
warnings.warn(
"The `add_route` method is deprecated, and will be removed in version 1.0.0." # noqa: E501
"Refer to https://www.starlette.io/routing/#http-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)
route = Route(
path,
endpoint=endpoint,
Expand All @@ -786,11 +769,6 @@ def add_route(
def add_websocket_route(
self, path: str, endpoint: typing.Callable, name: typing.Optional[str] = None
) -> None: # pragma: no cover
warnings.warn(
"The `add_websocket_route` method is deprecated, and will be removed in version 1.0.0. Refer to " # noqa: E501
"https://www.starlette.io/routing/#websocket-routing for the recommended approach.", # noqa: E501
DeprecationWarning,
)
route = WebSocketRoute(path, endpoint=endpoint, name=name)
self.routes.append(route)

Expand Down Expand Up @@ -837,11 +815,6 @@ def decorator(func: typing.Callable) -> typing.Callable:
def add_event_handler(
self, event_type: str, func: typing.Callable
) -> None: # pragma: no cover
warnings.warn(
"The `add_event_handler` method is deprecated, and will be removed in version 1.0.0. " # noqa: E501
"Refer to https://www.starlette.io/events/#registering-events for recommended approach.", # noqa: E501
DeprecationWarning,
)
assert event_type in ("startup", "shutdown")

if event_type == "startup":
Expand Down

0 comments on commit 51e22d6

Please sign in to comment.