-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Start using decorations for servlets #8646
Start using decorations for servlets #8646
Conversation
I'll keep this PR a draft until i've gotten some feedback from the synapse team on changing over servelet definitions to this kind. I can easily split this into a PR that adds the decoration and Some demonstrationclass TestServelet(ClientServlet):
@on("GET", "/path", v1=True, releases=(0, 1), unstable=False)
def most_verbose(self, request): ...
# note that v1 defaults to False in client_patterns
@on.post("/path/{argument}")
def with_argument(self, request, argument): ...
@on.put("/path/{argument_one}/{argument_two}")
def with_arguments(self, request, argument_one, argument_two): ...
@on.options("/path/{arg}(?:/.*)?")
def with_regex(self, request, arg): ...
@on.get({"/path", "/another_path"})
def more_paths(self, request, arg): ...
@on.get([
("/msc/1234/{argument}", {"unstable": True, "v1": False, "releases": []}),
("/stable_path/{argument}", dict(unstable=False, v1=True, releases=[1]))
])
def multiple_paths_with_different_prefixes(self, request, argument): ... The idea here is to make path definition, revision specificity, unstable tag, etc. all nearer and more idiomatic to the actual function. This echoes practices from modern web frameworks today by making handlers more clear to read and understand from a glance. |
(Thinking about it, I just realized I could also dump everything from Edit: (did that, i'll update comments to reflect new situation) |
One thought I had while making this: I see that most of these servlets are made to create GET/POST/PUT handlers under one path, but with the addition of these decorators, its possible to consolidate more handlers into less classes, in lesser files, making it possible to have more oversight on those handlers. I'm also looking at |
Just found out about #5118, i think pre-empting this before changing over to |
I think there's a couple of issues with this approach and I do not believe that we should pursue it:
I think that investigating something like #5118 is likely to pay bigger dividends than refactoring our URL registration. |
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>