Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions fgmetric/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,8 +12,6 @@
from fgmetric.collections import CounterPivotTable
from fgmetric.collections import DelimitedList

T = TypeVar("T", bound="Metric")


class Metric(
DelimitedList,
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions fgmetric/metric_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -43,7 +43,7 @@ class AlignmentMetric(Metric):

_metric_class: type[T]
_fout: TextIOWrapper
_writer: DictWriter
_writer: DictWriter[str]

def __init__(
self,
Expand Down Expand Up @@ -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:
Expand Down