7
7
from collections .abc import Sequence
8
8
from dataclasses import dataclass
9
9
from enum import Enum
10
- from typing import IO , Any , Optional , Union
10
+ from typing import IO , Any
11
11
12
12
import cyvcf2
13
13
import humanfriendly
@@ -33,7 +33,7 @@ def get_file_offset(vfp: int) -> int:
33
33
return vfp >> 16 & address_mask
34
34
35
35
36
- def read_bytes_as_value (f : IO [Any ], fmt : str , nodata : Optional [ Any ] = None ) -> Any :
36
+ def read_bytes_as_value (f : IO [Any ], fmt : str , nodata : Any | None = None ) -> Any :
37
37
"""Read bytes using a `struct` format string and return the unpacked data value.
38
38
39
39
Parameters
@@ -85,8 +85,8 @@ class Region:
85
85
"""
86
86
87
87
contig : str
88
- start : Optional [ int ] = None
89
- end : Optional [ int ] = None
88
+ start : int | None = None
89
+ end : int | None = None
90
90
91
91
def __post_init__ (self ):
92
92
if self .start is not None :
@@ -194,9 +194,7 @@ def get_first_locus_in_bin(csi: CSIIndex, bin: int) -> int:
194
194
return (bin - first_bin_on_level ) * (max_span // level_size ) + 1
195
195
196
196
197
- def read_csi (
198
- file : PathType , storage_options : Optional [dict [str , str ]] = None
199
- ) -> CSIIndex :
197
+ def read_csi (file : PathType , storage_options : dict [str , str ] | None = None ) -> CSIIndex :
200
198
"""Parse a CSI file into a `CSIIndex` object.
201
199
202
200
Parameters
@@ -311,7 +309,7 @@ def offsets(self) -> Any:
311
309
312
310
313
311
def read_tabix (
314
- file : PathType , storage_options : Optional [ dict [str , str ]] = None
312
+ file : PathType , storage_options : dict [str , str ] | None = None
315
313
) -> TabixIndex :
316
314
"""Parse a tabix file into a `TabixIndex` object.
317
315
@@ -452,7 +450,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
452
450
return False
453
451
454
452
def contig_record_counts (self ):
455
- d = dict (zip (self .sequence_names , self .index .record_counts ))
453
+ d = dict (zip (self .sequence_names , self .index .record_counts , strict = True ))
456
454
if self .file_type == VcfFileType .BCF :
457
455
d = {k : v for k , v in d .items () if v > 0 }
458
456
return d
@@ -483,8 +481,8 @@ def _filter_empty_and_refine(self, regions):
483
481
484
482
def partition_into_regions (
485
483
self ,
486
- num_parts : Optional [ int ] = None ,
487
- target_part_size : Union [ None , int , str ] = None ,
484
+ num_parts : int | None = None ,
485
+ target_part_size : None | int | str = None ,
488
486
):
489
487
if num_parts is None and target_part_size is None :
490
488
raise ValueError ("One of num_parts or target_part_size must be specified" )
0 commit comments