-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
In many of our tools, we have optional metric files that are written when an input path is given. This leads to having to have boilerplate for a nullcontext
from contextlib import nullcontext
with MetricWriter[SomeMetric](out_path, SomeMetric) if out_path is not None else nullcontext() as out_writer:
...
or having to condition on if the writer is built:
out_writer = (
None
if out_path is None
else (MetricWriter[SomeMetric](filename=out_path, metric_class=SomeMetric))
)
...
if out_writer is not None:
out_writer.write(...)
Can we instead have the writer accept out_path
as either Path
or None
, such that it can return a new MetricWriter
or nullcontext
?
ameynert
Metadata
Metadata
Assignees
Labels
No labels