Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a1901ab

Browse files
authored
Add documentation and type hints to parse_duration. (#9432)
1 parent c4a55ac commit a1901ab

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

changelog.d/9432.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add documentation and type hints to `parse_duration`.

synapse/config/_base.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from collections import OrderedDict
2222
from hashlib import sha256
2323
from textwrap import dedent
24-
from typing import Any, Iterable, List, MutableMapping, Optional
24+
from typing import Any, Iterable, List, MutableMapping, Optional, Union
2525

2626
import attr
2727
import jinja2
@@ -147,7 +147,20 @@ def parse_size(value):
147147
return int(value) * size
148148

149149
@staticmethod
150-
def parse_duration(value):
150+
def parse_duration(value: Union[str, int]) -> int:
151+
"""Convert a duration as a string or integer to a number of milliseconds.
152+
153+
If an integer is provided it is treated as milliseconds and is unchanged.
154+
155+
String durations can have a suffix of 's', 'm', 'h', 'd', 'w', or 'y'.
156+
No suffix is treated as milliseconds.
157+
158+
Args:
159+
value: The duration to parse.
160+
161+
Returns:
162+
The number of milliseconds in the duration.
163+
"""
151164
if isinstance(value, int):
152165
return value
153166
second = 1000

0 commit comments

Comments
 (0)