diff --git a/fgmetric/metric.py b/fgmetric/metric.py index 35f5543..e7b7401 100644 --- a/fgmetric/metric.py +++ b/fgmetric/metric.py @@ -3,8 +3,7 @@ from pathlib import Path from typing import Any from typing import Iterator -from typing import Type -from typing import TypeVar +from typing import Self from pydantic import BaseModel from pydantic import model_validator @@ -13,8 +12,6 @@ from fgmetric.collections import CounterPivotTable from fgmetric.collections import DelimitedList -T = TypeVar("T", bound="Metric") - class Metric( DelimitedList, @@ -59,7 +56,7 @@ class AlignmentMetric(Metric): """ @classmethod - def read(cls: Type[T], path: Path, delimiter: str = "\t") -> Iterator[T]: + def read(cls, path: Path, delimiter: str = "\t") -> Iterator[Self]: """Read Metric instances from file.""" # NOTE: the utf-8-sig encoding is required to auto-remove BOM from input file headers with path.open(encoding="utf-8-sig") as fin: diff --git a/fgmetric/metric_writer.py b/fgmetric/metric_writer.py index 98aaa65..01a1231 100644 --- a/fgmetric/metric_writer.py +++ b/fgmetric/metric_writer.py @@ -4,7 +4,7 @@ from pathlib import Path from types import TracebackType from typing import Iterable -from typing import Type +from typing import Self from fgmetric.metric import Metric @@ -43,7 +43,7 @@ class AlignmentMetric(Metric): _metric_class: type[T] _fout: TextIOWrapper - _writer: DictWriter + _writer: DictWriter[str] def __init__( self, @@ -77,12 +77,12 @@ def __init__( self._fout.close() raise - def __enter__(self) -> "MetricWriter": + def __enter__(self) -> Self: return self def __exit__( self, - exc_type: Type[BaseException] | None = None, + exc_type: type[BaseException] | None = None, exc_value: BaseException | None = None, traceback: TracebackType | None = None, ) -> None: