-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UrlDispatcher - add_routes returns a list of AbstractRoutes #4141
Changes from 2 commits
4cf126d
1920bd6
3d1d6b2
a0694c3
ecb1248
f046d42
1deafb3
1fdb169
43fe35d
2846b45
bfa97ee
16ead65
dcc9b80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
`web.UrlDispatcher.add_routes` and `web.Application.add_routes` return a list | ||
of registered `AbstractRoute` instances. `RouteDef.register` returns the | ||
registered resource. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,5 +274,6 @@ Young-Ho Cha | |
Yuriy Shatrov | ||
Yury Selivanov | ||
Yusuke Tsutsumi | ||
Zlatan Sičanica | ||
Марк Коренберг | ||
Семён Марьясин |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,14 @@ | |
from .typedefs import PathLike | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from .web_urldispatcher import UrlDispatcher | ||
from .web_urldispatcher import ( | ||
UrlDispatcher, | ||
AbstractRoute | ||
) | ||
from .web_request import Request | ||
from .web_response import StreamResponse | ||
else: | ||
Request = StreamResponse = UrlDispatcher = None | ||
Request = StreamResponse = UrlDispatcher = AbstractRoute = None | ||
|
||
|
||
__all__ = ('AbstractRouteDef', 'RouteDef', 'StaticDef', 'RouteTableDef', | ||
|
@@ -36,7 +39,7 @@ | |
|
||
class AbstractRouteDef(abc.ABC): | ||
@abc.abstractmethod | ||
def register(self, router: UrlDispatcher) -> None: | ||
def register(self, router: UrlDispatcher) -> Optional[AbstractRoute]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is basically the part I have the most questions about. So far, I've made this return value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pass # pragma: no cover | ||
|
||
|
||
|
@@ -59,13 +62,13 @@ def __repr__(self) -> str: | |
"{info}>".format(method=self.method, path=self.path, | ||
handler=self.handler, info=''.join(info))) | ||
|
||
def register(self, router: UrlDispatcher) -> None: | ||
def register(self, router: UrlDispatcher) -> AbstractRoute: | ||
if self.method in hdrs.METH_ALL: | ||
reg = getattr(router, 'add_'+self.method.lower()) | ||
reg(self.path, self.handler, **self.kwargs) | ||
return reg(self.path, self.handler, **self.kwargs) | ||
else: | ||
router.add_route(self.method, self.path, self.handler, | ||
**self.kwargs) | ||
return router.add_route(self.method, self.path, self.handler, | ||
**self.kwargs) | ||
|
||
|
||
@attr.s(frozen=True, repr=False, slots=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1413,6 +1413,8 @@ duplicated like one using :meth:`Application.copy`. | |
The table is a :class:`list` of :class:`RouteDef` items or | ||
:class:`RouteTableDef`. | ||
|
||
Returns a :class:`list` of registered :class:`AbstractRoute` instances. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
The method is a shortcut for | ||
``app.router.add_routes(routes_table)``, see also | ||
:meth:`UrlDispatcher.add_routes`. | ||
|
@@ -1569,6 +1571,8 @@ Router is any object that implements :class:`AbstractRouter` interface. | |
The table is a :class:`list` of :class:`RouteDef` items or | ||
:class:`RouteTableDef`. | ||
|
||
Returns a :class:`list` of registered :class:`AbstractRoute` instances. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same |
||
|
||
.. versionadded:: 2.3 | ||
|
||
.. method:: add_get(path, handler, *, name=None, allow_head=True, **kwargs) | ||
|
@@ -2080,6 +2084,8 @@ The definition is created by functions like :func:`get` or | |
|
||
Abstract method, should be overridden by subclasses. | ||
|
||
Returns the registered resource. | ||
|
||
|
||
.. class:: RouteDef | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional
is bad here. The return type should be a strict list.