in privaterelay/cleaner_task.py [0:0]
def __init__(self, metric_name: str | None = None, report_name: str | None = None):
"""
Initialize a ReportItem.
The `metric_name` parameter sets the name of the entry when it appears as a
`dict` or JSON key. The default is `None`, which omits the entry from
reports.
The `report_name` parameter sets the name of the entry when it appears in a
report for humans. It can be omitted when `metric_name` is None.
"""
if metric_name and (
bad_chars := [c for c in metric_name if c not in _ITEM_KEY_CHAR_SET]
):
raise ValueError(
f"metric_name '{metric_name}' has disallowed character"
f"{'' if len(bad_chars) == 1 else 's'} '{''.join(sorted(bad_chars))}'"
)
if metric_name == "":
raise ValueError("metric_name is an empty string, should be None")
if metric_name is None and report_name is not None:
raise ValueError(f"report_name is '{report_name}', but metric_name is None")
if report_name == "":
raise ValueError("report_name is an empty string, should be None")
self.metric_name = metric_name
self.report_name = report_name