Skip to content

Commit 29376eb

Browse files
authored
Forbid implicit optional in typing (#449)
1 parent 7ea97ca commit 29376eb

File tree

18 files changed

+62
-52
lines changed

18 files changed

+62
-52
lines changed

webknossos/typecheck.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22
set -eEuo pipefail
33

4-
echo -n "Typecheck webknossos: "
5-
python -m mypy -p webknossos --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages
4+
echo "Typecheck webknossos..."
5+
python -m mypy -p webknossos --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages --no-implicit-optional
66

7-
echo -n "Typecheck tests: "
8-
python -m mypy -p tests --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages
7+
echo "Typecheck tests..."
8+
python -m mypy -p tests --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages --no-implicit-optional
99

10-
echo -n "Typecheck examples: "
11-
python -m mypy -p examples --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages
10+
echo "Typecheck examples..."
11+
python -m mypy -p examples --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages --no-implicit-optional

webknossos/webknossos/dataset/dataset.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def add_layer(
163163
self,
164164
layer_name: str,
165165
category: str,
166-
dtype_per_layer: Union[str, np.dtype, type] = None,
167-
dtype_per_channel: Union[str, np.dtype, type] = None,
168-
num_channels: int = None,
166+
dtype_per_layer: Optional[Union[str, np.dtype, type]] = None,
167+
dtype_per_channel: Optional[Union[str, np.dtype, type]] = None,
168+
num_channels: Optional[int] = None,
169169
**kwargs: Any,
170170
) -> Layer:
171171
"""
@@ -262,9 +262,9 @@ def get_or_add_layer(
262262
self,
263263
layer_name: str,
264264
category: str,
265-
dtype_per_layer: Union[str, np.dtype, type] = None,
266-
dtype_per_channel: Union[str, np.dtype, type] = None,
267-
num_channels: int = None,
265+
dtype_per_layer: Optional[Union[str, np.dtype, type]] = None,
266+
dtype_per_channel: Optional[Union[str, np.dtype, type]] = None,
267+
num_channels: Optional[int] = None,
268268
**kwargs: Any,
269269
) -> Layer:
270270
"""
@@ -409,7 +409,7 @@ def add_symlink_layer(
409409
self,
410410
foreign_layer: Union[str, Path, Layer],
411411
make_relative: bool = False,
412-
new_layer_name: str = None,
412+
new_layer_name: Optional[str] = None,
413413
) -> Layer:
414414
"""
415415
Creates a symlink to the data at `foreign_layer` which belongs to another dataset.
@@ -454,7 +454,9 @@ def add_symlink_layer(
454454
return self.layers[layer_name]
455455

456456
def add_copy_layer(
457-
self, foreign_layer: Union[str, Path, Layer], new_layer_name: str = None
457+
self,
458+
foreign_layer: Union[str, Path, Layer],
459+
new_layer_name: Optional[str] = None,
458460
) -> Layer:
459461
"""
460462
Copies the data at `foreign_layer` which belongs to another dataset to the current dataset.
@@ -495,8 +497,8 @@ def copy_dataset(
495497
self,
496498
new_dataset_path: Union[str, Path],
497499
scale: Optional[Tuple[float, float, float]] = None,
498-
block_len: int = None,
499-
file_len: int = None,
500+
block_len: Optional[int] = None,
501+
file_len: Optional[int] = None,
500502
compress: Optional[bool] = None,
501503
args: Optional[Namespace] = None,
502504
) -> "Dataset":

webknossos/webknossos/dataset/mag_view.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_view(
167167
self,
168168
offset: Optional[Vec3IntLike] = None,
169169
size: Optional[Vec3IntLike] = None,
170-
read_only: bool = None,
170+
read_only: Optional[bool] = None,
171171
) -> View:
172172
"""
173173
Returns a view that is limited to the specified bounding box.
@@ -261,7 +261,9 @@ def get_bounding_boxes_on_disk(
261261
self.close()
262262

263263
def compress(
264-
self, target_path: Union[str, Path] = None, args: Namespace = None
264+
self,
265+
target_path: Optional[Union[str, Path]] = None,
266+
args: Optional[Namespace] = None,
265267
) -> None:
266268
"""
267269
Compresses the files on disk. This has consequences for writing data (see `write`).

webknossos/webknossos/dataset/view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_view(
222222
self,
223223
offset: Vec3IntLike = Vec3Int(0, 0, 0),
224224
size: Optional[Vec3IntLike] = None,
225-
read_only: bool = None,
225+
read_only: Optional[bool] = None,
226226
) -> "View":
227227
"""
228228
Returns a view that is limited to the specified bounding box.
@@ -346,7 +346,7 @@ def _assert_bounds(
346346
self,
347347
offset: Vec3Int,
348348
size: Vec3Int,
349-
strict: bool = None,
349+
strict: Optional[bool] = None,
350350
) -> None:
351351
if strict is None:
352352
strict = self._is_bounded

webknossos/webknossos/skeleton/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def children(self) -> Iterator[GroupOrGraph]:
6565
def add_group(
6666
self,
6767
name: str,
68-
_enforced_id: int = None,
68+
_enforced_id: Optional[int] = None,
6969
) -> "Group":
7070
new_group = Group(name, nml=self._nml, enforced_id=_enforced_id)
7171
self._children.add(new_group)

webknossos/webknossos/skeleton/nml/from_skeleton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _random_color_rgba() -> Tuple[float, float, float, float]:
3535

3636
def from_skeleton(
3737
group: "Group",
38-
parameters: Dict[str, Any] = None,
38+
parameters: Optional[Dict[str, Any]] = None,
3939
volume_dict: Optional[Dict[str, Any]] = None,
4040
) -> NML:
4141
"""

wkcuber/typecheck.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -eEuo pipefail
3-
echo "Typecheck wkcuber module:"
4-
python -m mypy -p wkcuber --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages
53

6-
echo "Typecheck tests:"
7-
python -m mypy -p tests --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages
4+
echo "Typecheck wkcuber module..."
5+
python -m mypy -p wkcuber --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages --no-implicit-optional
6+
7+
echo "Typecheck tests..."
8+
python -m mypy -p tests --disallow-untyped-defs --show-error-codes --strict-equality --namespace-packages --no-implicit-optional

wkcuber/wkcuber/check_equality.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from argparse import ArgumentParser, Namespace
33
from pathlib import Path
4-
from typing import Any, Callable
4+
from typing import Any, Callable, Optional
55

66
from wkcuber.api.dataset import Dataset
77
from wkcuber.api.bounding_box import BoundingBox, BoundingBoxNamedTuple
@@ -80,7 +80,7 @@ def assert_equality_for_chunk(
8080

8181

8282
def check_equality(
83-
source_path: Path, target_path: Path, args: Namespace = None
83+
source_path: Path, target_path: Path, args: Optional[Namespace] = None
8484
) -> None:
8585

8686
logging.info(f"Comparing {source_path} with {target_path}")

wkcuber/wkcuber/compress.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shutil
44
import logging
55
from argparse import ArgumentParser, Namespace
6+
from typing import Optional
67
from os import makedirs
78

89
from wkcuber.api.dataset import Dataset
@@ -51,25 +52,25 @@ def compress_mag(
5152
layer_name: str,
5253
target_path: Path,
5354
mag: Mag,
54-
args: Namespace = None,
55+
args: Optional[Namespace] = None,
5556
) -> None:
5657
Dataset(source_path).get_layer(layer_name).get_mag(mag).compress(
5758
target_path=Path(target_path), args=args
5859
)
5960

6061

6162
def compress_mag_inplace(
62-
target_path: Path, layer_name: str, mag: Mag, args: Namespace = None
63+
target_path: Path, layer_name: str, mag: Mag, args: Optional[Namespace] = None
6364
) -> None:
6465
Dataset(target_path).get_layer(layer_name).get_mag(mag).compress(args=args)
6566

6667

6768
def compress_mags(
6869
source_path: Path,
6970
layer_name: str,
70-
target_path: Path = None,
71-
mags: List[Mag] = None,
72-
args: Namespace = None,
71+
target_path: Optional[Path] = None,
72+
mags: Optional[List[Mag]] = None,
73+
args: Optional[Namespace] = None,
7374
) -> None:
7475
if target_path is None:
7576
target = source_path.with_suffix(".tmp")

wkcuber/wkcuber/convert_knossos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
import logging
33
from pathlib import Path
4-
from typing import Tuple, cast
4+
from typing import Tuple, cast, Optional
55

66
import wkw
77
from argparse import ArgumentParser, Namespace
@@ -84,7 +84,7 @@ def convert_knossos(
8484
layer_name: str,
8585
dtype: str,
8686
mag: int = 1,
87-
args: Namespace = None,
87+
args: Optional[Namespace] = None,
8888
) -> None:
8989
source_knossos_info = KnossosDatasetInfo(source_path, dtype)
9090
target_wkw_info = WkwDatasetInfo(

0 commit comments

Comments
 (0)