diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2023-01-27 07:27:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-27 07:27:55 -0500 |
commit | 265735db9d7b0698a511fc9389db4d6f104f1aa8 (patch) | |
tree | ca495a3241d62ffa8da7cb29df90c467497ff8ed /synapse/streams | |
parent | Add missing type hints in tests (#14879) (diff) | |
download | synapse-265735db9d7b0698a511fc9389db4d6f104f1aa8.tar.xz |
Use an enum for direction. (#14927)
For better type safety we use an enum instead of strings to configure direction (backwards or forwards).
Diffstat (limited to 'synapse/streams')
-rw-r--r-- | synapse/streams/config.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/streams/config.py b/synapse/streams/config.py index 6df2de919c..5cb7875181 100644 --- a/synapse/streams/config.py +++ b/synapse/streams/config.py @@ -16,6 +16,7 @@ from typing import Optional import attr +from synapse.api.constants import Direction from synapse.api.errors import SynapseError from synapse.http.servlet import parse_integer, parse_string from synapse.http.site import SynapseRequest @@ -34,7 +35,7 @@ class PaginationConfig: from_token: Optional[StreamToken] to_token: Optional[StreamToken] - direction: str + direction: Direction limit: int @classmethod @@ -45,9 +46,13 @@ class PaginationConfig: default_limit: int, default_dir: str = "f", ) -> "PaginationConfig": - direction = parse_string( - request, "dir", default=default_dir, allowed_values=["f", "b"] + direction_str = parse_string( + request, + "dir", + default=default_dir, + allowed_values=[Direction.FORWARDS.value, Direction.BACKWARDS.value], ) + direction = Direction(direction_str) from_tok_str = parse_string(request, "from") to_tok_str = parse_string(request, "to") |