Skip to content

Commit ac4e184

Browse files
seismanweiji14
andauthored
Enable ruff's flake8-bugbear (B) rules (#2825)
Co-authored-by: Wei Ji <[email protected]>
1 parent f724be4 commit ac4e184

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

examples/gallery/images/rgb_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Subset to area of Lāhainā in EPSG:32604 coordinates
2929
image = img.rio.clip_box(minx=738000, maxx=755000, miny=2300000, maxy=2318000)
3030
image = image.load() # Force loading the DataArray into memory
31-
image
31+
image # noqa: B018
3232

3333
# %%
3434
# Plot the RGB imagery:

pygmt/clib/conversion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def dataarray_to_matrix(grid):
103103
"but GMT only supports regular spacing. Calculated regular spacing "
104104
f"{coord_inc} is assumed in the '{dim}' dimension."
105105
)
106-
warnings.warn(msg, category=RuntimeWarning)
106+
warnings.warn(msg, category=RuntimeWarning, stacklevel=2)
107107
if coord_inc == 0:
108108
raise GMTInvalidInput(
109109
f"Grid has a zero increment in the '{dim}' dimension."

pygmt/clib/session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def create(self, name):
348348
"""
349349
try:
350350
# Won't raise an exception if there is a currently open session
351-
self.session_pointer
351+
_ = self.session_pointer
352352
# In this case, fail to create a new session until the old one is
353353
# destroyed
354354
raise GMTCLibError(

pygmt/tests/test_clib.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def mock_get_libgmt_func(name, argtypes=None, restype=None):
5656
return mock_func
5757
return get_libgmt_func(name, argtypes, restype)
5858

59-
setattr(session, "get_libgmt_func", mock_get_libgmt_func)
59+
session.get_libgmt_func = mock_get_libgmt_func
6060

6161
yield
6262

63-
setattr(session, "get_libgmt_func", get_libgmt_func)
63+
session.get_libgmt_func = get_libgmt_func
6464

6565

6666
def test_getitem():
@@ -94,12 +94,12 @@ def test_create_destroy_session():
9494
ses = clib.Session()
9595
for __ in range(2):
9696
with pytest.raises(GMTCLibNoSessionError):
97-
ses.session_pointer
97+
_ = ses.session_pointer
9898
ses.create("session1")
9999
assert ses.session_pointer is not None
100100
ses.destroy()
101101
with pytest.raises(GMTCLibNoSessionError):
102-
ses.session_pointer
102+
_ = ses.session_pointer
103103

104104

105105
def test_create_session_fails():
@@ -183,7 +183,7 @@ def test_method_no_session():
183183
with pytest.raises(GMTCLibNoSessionError):
184184
lib.call_module("gmtdefaults", "")
185185
with pytest.raises(GMTCLibNoSessionError):
186-
lib.session_pointer
186+
_ = lib.session_pointer
187187

188188

189189
def test_parse_constant_single():

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ line-ending = "lf" # Use UNIX `\n` line endings for all files
9595

9696
[tool.ruff.lint]
9797
select = [
98+
"B", # flake8-bugbear
9899
"E", # pycodestyle
99100
"F", # pyflakes
100101
"I", # isort

0 commit comments

Comments
 (0)