From 35265bb843f1a28ceb376a82bf610190b877ea62 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 18 Feb 2021 07:48:06 -0500 Subject: [PATCH 1/2] Add documentation and type hints to parse_duration. --- synapse/config/_base.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 97399eb9ba94..e89decda3480 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -21,7 +21,7 @@ from collections import OrderedDict from hashlib import sha256 from textwrap import dedent -from typing import Any, Iterable, List, MutableMapping, Optional +from typing import Any, Iterable, List, MutableMapping, Optional, Union import attr import jinja2 @@ -147,7 +147,20 @@ def parse_size(value): return int(value) * size @staticmethod - def parse_duration(value): + def parse_duration(value: Union[str, int]) -> int: + """Convert a duration as a string or integer to a number of milliseconds. + + If an integer is provided it is treated as milliseconds and is unchanged. + + String durations can have a suffix of 's', 'm', 'h', 'd', 'w', or 'y'. + No suffix is treated as milliseconds. + + Args: + value: The duration to parse. + + Returns: + The number of milliseconds in the duration. + """ if isinstance(value, int): return value second = 1000 From 15eb80fe44304afa274cc140ecfb5c551241af6a Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 18 Feb 2021 07:49:12 -0500 Subject: [PATCH 2/2] Newsfragment --- changelog.d/9432.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9432.misc diff --git a/changelog.d/9432.misc b/changelog.d/9432.misc new file mode 100644 index 000000000000..1e07da203332 --- /dev/null +++ b/changelog.d/9432.misc @@ -0,0 +1 @@ +Add documentation and type hints to `parse_duration`.