Skip to content

Commit 0a9000d

Browse files
tomwhitejeromekelleher
authored andcommitted
Don't add strict=False to zips (B905)
1 parent 6b4efba commit 0a9000d

File tree

7 files changed

+26
-30
lines changed

7 files changed

+26
-30
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ indent-width = 4
7575
[tool.ruff.lint]
7676
select = ["E", "F", "B", "W", "I", "N", "UP", "A", "PT"]
7777
#Allow uppercase names for e.g. call_AD
78-
ignore = ["N806", "N802", "N803", "A001", "A002"]
78+
#Don't add strict=False to zips (B905)
79+
ignore = ["N806", "N802", "N803", "A001", "A002", "B905", "RUF", "UP038"]
7980

8081
fixable = ["ALL"]
8182
unfixable = []

tests/test_regions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import pytest
42

53
from vcztools.regions import parse_region_string
@@ -15,6 +13,6 @@
1513
],
1614
)
1715
def test_parse_region_string(
18-
targets: str, expected: tuple[str, Optional[int], Optional[int]]
16+
targets: str, expected: tuple[str, int | None, int | None]
1917
):
2018
assert parse_region_string(targets) == expected

vcztools/query.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
22
import itertools
33
import math
4-
from typing import Callable, Optional, Union
4+
from collections.abc import Callable
55

66
import numpy as np
77
import pyparsing as pp
@@ -232,7 +232,7 @@ def generate(chunk_data):
232232
return generate
233233

234234
def _compose_element_generator(
235-
self, element: Union[str, pp.ParseResults], *, sample_loop=False
235+
self, element: str | pp.ParseResults, *, sample_loop=False
236236
) -> Callable:
237237
if isinstance(element, pp.ParseResults):
238238
if element.get_name() == "subfield":
@@ -287,8 +287,8 @@ def write_query(
287287
output,
288288
*,
289289
query_format: str,
290-
include: Optional[str] = None,
291-
exclude: Optional[str] = None,
290+
include: str | None = None,
291+
exclude: str | None = None,
292292
):
293293
root = zarr.open(vcz, mode="r")
294294
filter_expr = filter_mod.FilterExpression(

vcztools/regions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import re
2-
from typing import Any, Optional
2+
from typing import Any
33

44
import numpy as np
55
import pandas as pd
66
from pyranges import PyRanges
77

88

9-
def parse_region_string(region: str) -> tuple[str, Optional[int], Optional[int]]:
9+
def parse_region_string(region: str) -> tuple[str, int | None, int | None]:
1010
"""Return the contig, start position and end position from a region string."""
1111
if re.search(r":\d+-\d*$", region):
1212
contig, start_end = region.rsplit(":", 1)
@@ -21,7 +21,7 @@ def parse_region_string(region: str) -> tuple[str, Optional[int], Optional[int]]
2121

2222

2323
def regions_to_pyranges(
24-
regions: list[tuple[str, Optional[int], Optional[int]]], all_contigs: list[str]
24+
regions: list[tuple[str, int | None, int | None]], all_contigs: list[str]
2525
) -> PyRanges:
2626
"""Convert region tuples to a PyRanges object."""
2727

@@ -44,7 +44,7 @@ def regions_to_pyranges(
4444
return PyRanges(chromosomes=chromosomes, starts=starts, ends=ends)
4545

4646

47-
def parse_regions(regions: Optional[str], all_contigs: list[str]) -> Optional[PyRanges]:
47+
def parse_regions(regions: str | None, all_contigs: list[str]) -> PyRanges | None:
4848
"""Return a PyRanges object from a comma-separated set of region strings."""
4949
if regions is None:
5050
return None
@@ -54,8 +54,8 @@ def parse_regions(regions: Optional[str], all_contigs: list[str]) -> Optional[Py
5454

5555

5656
def parse_targets(
57-
targets: Optional[str], all_contigs: list[str]
58-
) -> tuple[Optional[PyRanges], bool]:
57+
targets: str | None, all_contigs: list[str]
58+
) -> tuple[PyRanges | None, bool]:
5959
"""Return a PyRanges object from a comma-separated set of region strings,
6060
optionally preceeded by a ^ character to indicate complement."""
6161
if targets is None:
@@ -68,8 +68,8 @@ def parse_targets(
6868

6969

7070
def regions_to_chunk_indexes(
71-
regions: Optional[PyRanges],
72-
targets: Optional[PyRanges],
71+
regions: PyRanges | None,
72+
targets: PyRanges | None,
7373
complement: bool,
7474
regions_index: Any,
7575
):
@@ -113,8 +113,8 @@ def regions_to_chunk_indexes(
113113

114114

115115
def regions_to_selection(
116-
regions: Optional[PyRanges],
117-
targets: Optional[PyRanges],
116+
regions: PyRanges | None,
117+
targets: PyRanges | None,
118118
complement: bool,
119119
variant_contig: Any,
120120
variant_position: Any,

vcztools/retrieval.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import collections.abc
2-
from typing import Optional
32

43
import numpy as np
54
import zarr
@@ -140,8 +139,8 @@ def variant_chunk_index_iter_with_filtering(
140139
*,
141140
variant_regions=None,
142141
variant_targets=None,
143-
include: Optional[str] = None,
144-
exclude: Optional[str] = None,
142+
include: str | None = None,
143+
exclude: str | None = None,
145144
):
146145
"""Iterate over variant chunk indexes that overlap the given regions or targets
147146
and which match the include/exclude filter expression.
@@ -179,11 +178,11 @@ def variant_chunk_index_iter_with_filtering(
179178
def variant_chunk_iter(
180179
root,
181180
*,
182-
fields: Optional[list[str]] = None,
181+
fields: list[str] | None = None,
183182
variant_regions=None,
184183
variant_targets=None,
185-
include: Optional[str] = None,
186-
exclude: Optional[str] = None,
184+
include: str | None = None,
185+
exclude: str | None = None,
187186
samples_selection=None,
188187
):
189188
query_fields_reader = VariantChunkReader(root, fields=fields)

vcztools/samples.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Optional
32

43
import numpy as np
54

@@ -9,8 +8,8 @@
98

109

1110
def parse_samples(
12-
samples: Optional[str], all_samples: np.ndarray, *, force_samples: bool = True
13-
) -> tuple[np.ndarray, Optional[np.ndarray]]:
11+
samples: str | None, all_samples: np.ndarray, *, force_samples: bool = True
12+
) -> tuple[np.ndarray, np.ndarray | None]:
1413
"""Parse a bcftools-style samples string.
1514
1615
Returns an array of the sample IDs, and an array indicating the selection

vcztools/vcf_writer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
import sys
55
from datetime import datetime
6-
from typing import Optional
76

87
import numpy as np
98
import zarr
@@ -86,8 +85,8 @@ def write_vcf(
8685
samples=None,
8786
force_samples: bool = False,
8887
drop_genotypes: bool = False,
89-
include: Optional[str] = None,
90-
exclude: Optional[str] = None,
88+
include: str | None = None,
89+
exclude: str | None = None,
9190
) -> None:
9291
"""Convert a dataset to a VCF file.
9392

0 commit comments

Comments
 (0)