Skip to content

Commit ae015f5

Browse files
committed
Typing: Add overload to Router.add() for function-style endpoints
1 parent f5c1109 commit ae015f5

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

rolo/routing/router.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,31 @@ def add(
166166
"""
167167
...
168168

169+
@overload
170+
def add(
171+
self,
172+
path: str,
173+
endpoint: t.Callable[[Request, ...], Response],
174+
host: t.Optional[str] = None,
175+
methods: t.Optional[t.Iterable[str]] = None,
176+
**kwargs,
177+
) -> Rule:
178+
"""
179+
Creates a new Rule from the given parameters and adds it to the URL Map.
180+
181+
TODO: many callers still expect ``add`` to return a single rule rather than a list, but it would be better to
182+
homogenize the API and make every method return a list.
183+
184+
:param path: the path pattern to match. This path rule, in contrast to the default behavior of Werkzeug, will be
185+
matched against the raw / original (potentially URL-encoded) path.
186+
:param endpoint: the function to invoke
187+
:param host: an optional host matching pattern. if not pattern is given, the rule matches any host
188+
:param methods: the allowed HTTP verbs for this rule
189+
:param kwargs: any other argument that can be passed to ``werkzeug.routing.Rule``
190+
:return: the rule that was created
191+
"""
192+
...
193+
169194
@overload
170195
def add(self, fn: _RouteEndpoint) -> list[Rule]:
171196
"""

0 commit comments

Comments
 (0)