Skip to content

Commit

Permalink
chore: type using self
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Dec 29, 2024
1 parent 914379d commit e8a1f75
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
from pysam import AlignedSegment
from pysam import AlignmentFile as SamFile
from pysam import AlignmentHeader as SamHeader
from typing_extensions import Self
from typing_extensions import deprecated

import fgpyo.io
Expand Down Expand Up @@ -1328,7 +1329,7 @@ def __post_init__(self) -> None:
raise ValueError(f"Mapping quality cannot be <0! Found: {self.mapq}")

@classmethod
def from_tag_part(cls, part: str) -> "SecondaryAlignment":
def from_tag_part(cls, part: str) -> Self:
"""Build a secondary alignment from a single `XA` or `XB` tag part.
Args:
Expand Down Expand Up @@ -1359,7 +1360,7 @@ def from_tag_part(cls, part: str) -> "SecondaryAlignment":
)

@classmethod
def many_from_tag(cls, value: str) -> list["SecondaryAlignment"]:
def many_from_tag(cls, value: str) -> list[Self]:
"""Build many secondary alignments from a single `XA` or `XB` tag value.
Args:
Expand All @@ -1368,13 +1369,13 @@ def many_from_tag(cls, value: str) -> list["SecondaryAlignment"]:
return [cls.from_tag_part(part) for part in value.rstrip(";").split(";")]

@classmethod
def many_from_rec(cls, rec: AlignedSegment) -> list["SecondaryAlignment"]:
def many_from_rec(cls, rec: AlignedSegment) -> list[Self]:
"""Build many secondary alignments from a single SAM record.
Args:
rec: The SAM record to generate secondary alignments from.
"""
secondaries: list["SecondaryAlignment"] = []
secondaries: list[Self] = []
if rec.has_tag("XA"):
secondaries.extend(cls.many_from_tag(cast(str, rec.get_tag("XA"))))
if rec.has_tag("XB"):
Expand Down

0 comments on commit e8a1f75

Please sign in to comment.