From 9f358e48a03f27aaf0988d909d56b705f05a431d Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Fri, 25 Oct 2024 13:53:57 -0700 Subject: [PATCH] Introduce Comparable protocol --- src/aligntools/cigar_hit.py | 3 ++- src/aligntools/comparable.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/aligntools/comparable.py diff --git a/src/aligntools/cigar_hit.py b/src/aligntools/cigar_hit.py index 88078ca..d6f99aa 100644 --- a/src/aligntools/cigar_hit.py +++ b/src/aligntools/cigar_hit.py @@ -12,6 +12,7 @@ from aligntools.coordinate_mapping import CoordinateMapping from aligntools.cigar_actions import CigarActions from aligntools.cigar import Cigar +from aligntools.comparable import Comparable import aligntools.exceptions as ex @@ -397,7 +398,7 @@ def __str__(self): def drop_overlapping_cigar_hits(cigar_hits: Iterable[CigarHit], - quality: Callable[[CigarHit], int]) \ + quality: Callable[[CigarHit], Comparable]) \ -> Iterator[CigarHit]: """ Filter overlapping CigarHit objects based on a quality criterion. diff --git a/src/aligntools/comparable.py b/src/aligntools/comparable.py new file mode 100644 index 0000000..c97ffcd --- /dev/null +++ b/src/aligntools/comparable.py @@ -0,0 +1,13 @@ +from typing import Protocol, TypeVar, runtime_checkable + +T = TypeVar('T', bound='Comparable') + + +@runtime_checkable +class Comparable(Protocol): + def __lt__(self, other: T) -> bool: ... + def __le__(self, other: T) -> bool: ... + def __gt__(self, other: T) -> bool: ... + def __ge__(self, other: T) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ...