Skip to content

Commit

Permalink
ENH: Add None to b-vals iterators size parameter annotations
Browse files Browse the repository at this point in the history
Add `None` to b-vals iterators `size` parameter annotations.

Fixes:
```
src/nifreeze/utils.py:30: error:
 Incompatible default for argument "size" (default has type "None", argument has type "int")  [assignment]
src/nifreeze/utils.py:30: note:
 PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/nifreeze/utils.py:30: note:
 Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/nifreeze/utils.py:59: error:
 Incompatible default for argument "size" (default has type "None", argument has type "int")  [assignment]
src/nifreeze/utils.py:59:
 note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/nifreeze/utils.py:59:
 note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/nifreeze/utils.py:108:
 error: Incompatible default for argument "size" (default has type "None", argument has type "int")  [assignment]
src/nifreeze/utils.py:108:
 note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/nifreeze/utils.py:108:
 note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/nifreeze/utils.py:135:
 error: Incompatible default for argument "size" (default has type "None", argument has type "int")  [assignment]
src/nifreeze/utils.py:135:
 note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/nifreeze/utils.py:135:
 note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
```

raised for example in:
https://github.com/nipreps/nifreeze/actions/runs/12437972140/job/34728973936#step:8:32
  • Loading branch information
jhlegarreta committed Dec 22, 2024
1 parent 6b6ba70 commit e813b66
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/nifreeze/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
from typing import Iterator


def linear_iterator(size: int = None, **kwargs) -> Iterator[int]:
def linear_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
"""
Traverse the dataset volumes in ascending order.
Parameters
----------
size : :obj:`int`
Number of volumes in the dataset
(for instance, the number of orientations in a DWI)
size : :obj:`int` or None, optional
Number of volumes in the dataset (for instance, the number of
orientations in a DWI). If `None`, the size is inferred from the `bvals`
argument in `kwargs`, if present.
Returns
-------
Expand All @@ -56,20 +57,21 @@ def linear_iterator(size: int = None, **kwargs) -> Iterator[int]:
return range(size)


def random_iterator(size: int = None, **kwargs) -> Iterator[int]:
def random_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
"""
Traverse the dataset volumes randomly.
If the `seed` key is present in the keyword arguments, initializes the seed
of Python's `random` pseudo-random number generator library with the given
value. Specifically, if `False`, `None` is used as the seed; it `True`, a
default seed value is used.
Parameters
----------
size : :obj:`int`
Number of volumes in the dataset
(for instance, the number of orientations in a DWI)
seed : :obj:`int` or :obj:`bool` or :obj:`bool` or ``None``
If :obj:`int` or :obj:`str` or ``None``, initializes the seed of Python's random generator
with the given value.
If ``False``, the random generator is passed ``None``.
If ``True``, a default seed value is set.
size : :obj:`int` or None, optional
Number of volumes in the dataset (for instance, the number of
orientations in a DWI). If `None`, the size is inferred from the `bvals`
argument in `kwargs`, if present.
Returns
-------
Expand Down Expand Up @@ -105,7 +107,7 @@ def random_iterator(size: int = None, **kwargs) -> Iterator[int]:
return (x for x in index_order)


def bvalue_iterator(size: int = None, **kwargs) -> Iterator[int]:
def bvalue_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
"""
Traverse the volumes in a DWI dataset by growing b-value.
Expand All @@ -132,15 +134,16 @@ def bvalue_iterator(size: int = None, **kwargs) -> Iterator[int]:
return (index[1] for index in indexed_bvals)


def centralsym_iterator(size: int = None, **kwargs) -> Iterator[int]:
def centralsym_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
"""
Traverse the dataset starting from the center and alternatingly progressing to the sides.
Parameters
----------
size : :obj:`int`
Number of volumes in the dataset
(for instance, the number of orientations in a DWI)
size : :obj:`int` or None, optional
Number of volumes in the dataset (for instance, the number of
orientations in a DWI). If `None`, the size is inferred from the `bvals`
argument in `kwargs`, if present.
Returns
-------
Expand Down

0 comments on commit e813b66

Please sign in to comment.