Skip to content

Commit

Permalink
chore: update type hinting to py3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 16, 2023
1 parent 54996b8 commit aa2aae4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fasta_checksum_utils/_contig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pysam
from typing import Generator, Tuple
from typing import Generator
from .algorithms import ChecksumAlgorithm


Expand All @@ -12,7 +12,7 @@
SEQUENCE_CHUNK_SIZE = 128 * 1024 # 128 KB of bases at a time


async def checksum_contig(fh: pysam.FastaFile, contig_name: str, algorithms: Tuple[ChecksumAlgorithm, ...]):
async def checksum_contig(fh: pysam.FastaFile, contig_name: str, algorithms: tuple[ChecksumAlgorithm, ...]):
contig_length = fh.get_reference_length(contig_name)

def gen_sequence() -> Generator[bytes, None, None]:
Expand Down
3 changes: 1 addition & 2 deletions fasta_checksum_utils/_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio
from pathlib import Path
from typing import Tuple
from .algorithms import ChecksumAlgorithm


async def checksum_file(file: Path, algorithms: Tuple[ChecksumAlgorithm, ...]) -> Tuple[str, ...]:
async def checksum_file(file: Path, algorithms: tuple[ChecksumAlgorithm, ...]) -> tuple[str, ...]:
return tuple(await asyncio.gather(*(a.checksum_file(file) for a in algorithms)))
12 changes: 6 additions & 6 deletions fasta_checksum_utils/fasta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import pysam
from pathlib import Path
from typing import Dict, Tuple, Union
from typing import Union

from .algorithms import ChecksumAlgorithm
from ._contig import checksum_contig
Expand All @@ -12,16 +12,16 @@ class FastaReport:

def __init__(
self,
file_checksums: Dict[ChecksumAlgorithm, str],
file_checksums: dict[ChecksumAlgorithm, str],
file_size: int,
sequence_checksums_and_lengths: Dict[str, Tuple[Dict[ChecksumAlgorithm, str], int]],
sequence_checksums_and_lengths: dict[str, tuple[dict[ChecksumAlgorithm, str], int]],
):
self._file_checksums = file_checksums
self._file_size: int = file_size
self._sequence_checksums_and_lengths = sequence_checksums_and_lengths

def as_bento_json(self, genome_id: Union[str, None] = None) -> str:
def _checksum_dict(cs: Dict[ChecksumAlgorithm, str]) -> Dict[str, str]:
def _checksum_dict(cs: dict[ChecksumAlgorithm, str]) -> dict[str, str]:
return {str(algorithm).lower(): checksum for algorithm, checksum in cs.items()}

return json.dumps({
Expand Down Expand Up @@ -55,7 +55,7 @@ def as_text_report(self) -> str:
return text_report


async def fasta_report(file: Path, algorithms: Tuple[ChecksumAlgorithm, ...]) -> FastaReport:
async def fasta_report(file: Path, algorithms: tuple[ChecksumAlgorithm, ...]) -> FastaReport:
file_size = file.stat().st_size

# Calculate whole-file checksums
Expand All @@ -66,7 +66,7 @@ async def fasta_report(file: Path, algorithms: Tuple[ChecksumAlgorithm, ...]) ->
# Calculate sequence content checksums

fh = pysam.FastaFile(str(file))
sequence_checksums_and_lengths: Dict[str, Tuple[Dict[ChecksumAlgorithm, str], int]] = {}
sequence_checksums_and_lengths: dict[str, tuple[dict[ChecksumAlgorithm, str], int]] = {}

try:
for sequence_name in fh.references:
Expand Down

0 comments on commit aa2aae4

Please sign in to comment.