Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Apply ruff/flake8-bugbear rules (B) #1352

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nibabel/gifti/tests/test_parse_gifti_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_load_dataarray1():
me = img.darrays[0].meta
assert 'AnatomicalStructurePrimary' in me
assert 'AnatomicalStructureSecondary' in me
me['AnatomicalStructurePrimary'] == 'CortexLeft'
assert me['AnatomicalStructurePrimary'] == 'CortexLeft'
assert_array_almost_equal(img.darrays[0].coordsys.xform, np.eye(4, 4))
assert xform_codes.niistring[img.darrays[0].coordsys.dataspace] == 'NIFTI_XFORM_TALAIRACH'
assert xform_codes.niistring[img.darrays[0].coordsys.xformspace] == 'NIFTI_XFORM_TALAIRACH'
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_load_dataarray4():
def test_dataarray5():
img5 = load(DATA_FILE5)
for da in img5.darrays:
gifti_endian_codes.byteorder[da.endian] == 'little'
assert gifti_endian_codes.byteorder[da.endian] == 'little'
assert_array_almost_equal(img5.darrays[0].data, DATA_FILE5_darr1)
assert_array_almost_equal(img5.darrays[1].data, DATA_FILE5_darr2)
# Round trip tested below
Expand Down
2 changes: 1 addition & 1 deletion nibabel/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Generate dynamic fixtures
def pytest_generate_tests(metafunc):
if 'supported_dtype' in metafunc.fixturenames:
if metafunc.cls is None or not getattr(metafunc.cls, 'image_class'):
if metafunc.cls is None or not metafunc.cls.image_class:
raise pytest.UsageError(
'Attempting to use supported_dtype fixture outside an image test case'
)
Expand Down
6 changes: 3 additions & 3 deletions nibabel/tests/test_openers.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,17 @@ def test_DeterministicGzipFile_fileobj():
with open('test.gz', 'wb') as fobj:
with DeterministicGzipFile(filename='', mode='wb', fileobj=fobj) as gzobj:
gzobj.write(msg)
md5sum('test.gz') == ref_chksum
assert md5sum('test.gz') == ref_chksum

with open('test.gz', 'wb') as fobj:
with DeterministicGzipFile(fileobj=fobj, mode='wb') as gzobj:
gzobj.write(msg)
md5sum('test.gz') == ref_chksum
assert md5sum('test.gz') == ref_chksum

with open('test.gz', 'wb') as fobj:
with DeterministicGzipFile(filename='test.gz', mode='wb', fileobj=fobj) as gzobj:
gzobj.write(msg)
md5sum('test.gz') == ref_chksum
assert md5sum('test.gz') == ref_chksum


def test_bitwise_determinism():
Expand Down
2 changes: 1 addition & 1 deletion nibabel/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def _set_position(self, x, y, z, notify=True):
# Matplotlib handlers ####################################################
def _in_axis(self, event):
"""Return axis index if within one of our axes, else None"""
if getattr(event, 'inaxes') is None:
if event.inaxes is None:
return None
for ii, ax in enumerate(self._axes):
if event.inaxes is ax:
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,23 @@ exclude = ["doc", "nibabel/externals", "tools", "version.py", "versioneer.py"]

[tool.ruff.lint]
select = [
"B",
"F",
"I",
"Q",
"UP",
]
ignore = [
"B006", # TODO: enable
"B008", # TODO: enable
"B007",
"B011",
"B017", # TODO: enable
"B018",
"B020",
"B023", # TODO: enable
"B028",
"B904",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand Down
Loading