File tree 1 file changed +14
-0
lines changed
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 116
116
117
117
"""
118
118
119
+ import dataclasses
119
120
from abc import ABC
120
121
from enum import Enum
121
122
from pathlib import Path
127
128
from typing import List
128
129
from typing import TypeVar
129
130
131
+ import attr
132
+
130
133
from fgpyo import io
131
134
from fgpyo .util import inspect
132
135
@@ -334,3 +337,14 @@ def fast_concat(*inputs: Path, output: Path) -> None:
334
337
io .write_lines (
335
338
path = output , lines_to_write = list (io .read_lines (input_path ))[1 :], append = True
336
339
)
340
+
341
+
342
+ def asdict (metric : Metric ) -> dict [str , Any ]:
343
+ """Convert a Metric instance to a dictionary."""
344
+
345
+ if dataclasses .is_dataclass (metric ):
346
+ return dataclasses .asdict (metric )
347
+ elif attr .has (metric ):
348
+ return attr .asdict (metric )
349
+ else :
350
+ assert False , "Unreachable"
You can’t perform that action at this time.
0 commit comments