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
10
+ from typing import IO , Any , Optional , Union
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 : Any | None = None ) -> Any :
36
+ def read_bytes_as_value (f : IO [Any ], fmt : str , nodata : Optional [ Any ] = 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 : int | None = None
89
- end : int | None = None
88
+ start : Optional [ int ] = None
89
+ end : Optional [ int ] = None
90
90
91
91
def __post_init__ (self ):
92
92
if self .start is not None :
@@ -194,7 +194,9 @@ 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 (file : PathType , storage_options : dict [str , str ] | None = None ) -> CSIIndex :
197
+ def read_csi (
198
+ file : PathType , storage_options : Optional [dict [str , str ]] = None
199
+ ) -> CSIIndex :
198
200
"""Parse a CSI file into a `CSIIndex` object.
199
201
200
202
Parameters
@@ -309,7 +311,7 @@ def offsets(self) -> Any:
309
311
310
312
311
313
def read_tabix (
312
- file : PathType , storage_options : dict [str , str ] | None = None
314
+ file : PathType , storage_options : Optional [ dict [str , str ]] = None
313
315
) -> TabixIndex :
314
316
"""Parse a tabix file into a `TabixIndex` object.
315
317
@@ -450,7 +452,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
450
452
return False
451
453
452
454
def contig_record_counts (self ):
453
- d = dict (zip (self .sequence_names , self .index .record_counts , strict = True ))
455
+ d = dict (zip (self .sequence_names , self .index .record_counts ))
454
456
if self .file_type == VcfFileType .BCF :
455
457
d = {k : v for k , v in d .items () if v > 0 }
456
458
return d
@@ -481,8 +483,8 @@ def _filter_empty_and_refine(self, regions):
481
483
482
484
def partition_into_regions (
483
485
self ,
484
- num_parts : int | None = None ,
485
- target_part_size : None | int | str = None ,
486
+ num_parts : Optional [ int ] = None ,
487
+ target_part_size : Union [ None , int , str ] = None ,
486
488
):
487
489
if num_parts is None and target_part_size is None :
488
490
raise ValueError ("One of num_parts or target_part_size must be specified" )
0 commit comments