Skip to content

Commit

Permalink
Autoupdate pre-commit hooks (#1097)
Browse files Browse the repository at this point in the history
* Autoupdate pre-commit hooks

updates:
- [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0)
- [github.com/asottile/pyupgrade: v3.7.0 → v3.9.0](asottile/pyupgrade@v3.7.0...v3.9.0)
- [github.com/asottile/setup-cfg-fmt: v2.3.0 → v2.4.0](asottile/setup-cfg-fmt@v2.3.0...v2.4.0)
- [github.com/PyCQA/docformatter: v1.7.3 → v1.7.5](PyCQA/docformatter@v1.7.3...v1.7.5)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jul 25, 2023
1 parent 322abcf commit 07a1b06
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
exclude: setup.cfg

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black

Expand Down Expand Up @@ -55,13 +55,13 @@ repos:
- id: rst-inline-touching-normal # detect mistake of inline code touching normal text in rst

- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
rev: v3.9.0
hooks:
- id: pyupgrade
args: ['--py37-plus', '--keep-runtime-typing']

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.3.0
rev: v2.4.0
hooks:
- id: setup-cfg-fmt
args: ['--include-version-classifiers']
Expand All @@ -72,7 +72,7 @@ repos:
- id: doc8

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.3
rev: v1.7.5
hooks:
- id: docformatter

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand Down Expand Up @@ -51,7 +50,7 @@ install_requires =
torch>=1.1
tqdm
typer[all]
python_requires = >=3.7
python_requires = >=3.8
include_package_data = True
zip_safe = False

Expand Down
8 changes: 3 additions & 5 deletions src/torchio/data/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ def __init__(

if type is None:
warnings.warn(
(
'Not specifying the image type is deprecated and will be'
' mandatory in the future. You can probably use'
' tio.ScalarImage or tio.LabelMap instead'
),
'Not specifying the image type is deprecated and will be'
' mandatory in the future. You can probably use'
' tio.ScalarImage or tio.LabelMap instead',
DeprecationWarning,
stacklevel=2,
)
Expand Down
6 changes: 2 additions & 4 deletions src/torchio/data/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ def __init__(

if self.shuffle_subjects and self.subject_sampler is not None:
raise ValueError(
(
'The flag shuffle_subjects cannot be set'
' when a subject sampler is passed'
),
'The flag shuffle_subjects cannot be set'
' when a subject sampler is passed',
)

def __len__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ def parse_gaussian_parameter(
min_value, max_value = nums_range
if min_value > max_value:
raise ValueError(
(
f'If {name} is a sequence, the second value must be'
f' equal or greater than the first, not {nums_range}'
),
f'If {name} is a sequence, the second value must be'
f' equal or greater than the first, not {nums_range}',
)
return min_value, max_value

Expand Down
54 changes: 18 additions & 36 deletions src/torchio/transforms/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,32 +281,24 @@ def _parse_range(
if isinstance(nums_range, numbers.Number): # single number given
if nums_range < 0:
raise ValueError(
(
f'If {name} is a single number,'
f' it must be positive, not {nums_range}'
),
f'If {name} is a single number,'
f' it must be positive, not {nums_range}',
)
if min_constraint is not None and nums_range < min_constraint:
raise ValueError(
(
f'If {name} is a single number, it must be greater'
f' than {min_constraint}, not {nums_range}'
),
f'If {name} is a single number, it must be greater'
f' than {min_constraint}, not {nums_range}',
)
if max_constraint is not None and nums_range > max_constraint:
raise ValueError(
(
f'If {name} is a single number, it must be smaller'
f' than {max_constraint}, not {nums_range}'
),
f'If {name} is a single number, it must be smaller'
f' than {max_constraint}, not {nums_range}',
)
if type_constraint is not None:
if not isinstance(nums_range, type_constraint):
raise ValueError(
(
f'If {name} is a single number, it must be of'
f' type {type_constraint}, not {nums_range}'
),
f'If {name} is a single number, it must be of'
f' type {type_constraint}, not {nums_range}',
)
min_range = -nums_range if min_constraint is None else nums_range
return (min_range, nums_range)
Expand All @@ -315,10 +307,8 @@ def _parse_range(
min_value, max_value = nums_range # type: ignore[misc]
except (TypeError, ValueError):
raise ValueError(
(
f'If {name} is not a single number, it must be'
f' a sequence of len 2, not {nums_range}'
),
f'If {name} is not a single number, it must be'
f' a sequence of len 2, not {nums_range}',
)

min_is_number = isinstance(min_value, numbers.Number)
Expand All @@ -329,37 +319,29 @@ def _parse_range(

if min_value > max_value:
raise ValueError(
(
f'If {name} is a sequence, the second value must be'
f' equal or greater than the first, but it is {nums_range}'
),
f'If {name} is a sequence, the second value must be'
f' equal or greater than the first, but it is {nums_range}',
)

if min_constraint is not None and min_value < min_constraint:
raise ValueError(
(
f'If {name} is a sequence, the first value must be greater'
f' than {min_constraint}, but it is {min_value}'
),
f'If {name} is a sequence, the first value must be greater'
f' than {min_constraint}, but it is {min_value}',
)

if max_constraint is not None and max_value > max_constraint:
raise ValueError(
(
f'If {name} is a sequence, the second value must be'
f' smaller than {max_constraint}, but it is {max_value}'
),
f'If {name} is a sequence, the second value must be'
f' smaller than {max_constraint}, but it is {max_value}',
)

if type_constraint is not None:
min_type_ok = isinstance(min_value, type_constraint)
max_type_ok = isinstance(max_value, type_constraint)
if not min_type_ok or not max_type_ok:
raise ValueError(
(
f'If "{name}" is a sequence, its values must be of'
f' type "{type_constraint}", not "{type(nums_range)}"'
),
f'If "{name}" is a sequence, its values must be of'
f' type "{type_constraint}", not "{type(nums_range)}"',
)
return nums_range # type: ignore[return-value]

Expand Down

0 comments on commit 07a1b06

Please sign in to comment.