Skip to content

Commit 0a93029

Browse files
authored
Enable ruff's flake8-print (T20) rules (#2894)
1 parent 048700c commit 0a93029

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pygmt/clib/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def print_func(file_pointer, message):
381381
self._error_log.append(message)
382382
# flush to make sure the messages are printed even if we have a
383383
# crash.
384-
print(message, file=sys.stderr, flush=True)
384+
print(message, file=sys.stderr, flush=True) # noqa: T201
385385
return 0
386386

387387
# Need to store a copy of the function because ctypes doesn't and it

pygmt/tests/test_clib_virtualfiles.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_virtual_file_fails():
8080
with clib.Session() as lib, mock(lib, "GMT_Open_VirtualFile", returns=1):
8181
with pytest.raises(GMTCLibError):
8282
with lib.open_virtual_file(*vfargs):
83-
print("Should not get to this code")
83+
pass
8484

8585
# Test the status check when closing the virtual file
8686
# Mock the opening to return 0 (success) so that we don't open a file that
@@ -91,7 +91,6 @@ def test_virtual_file_fails():
9191
with pytest.raises(GMTCLibError):
9292
with lib.open_virtual_file(*vfargs):
9393
pass
94-
print("Shouldn't get to this code either")
9594

9695

9796
def test_virtual_file_bad_direction():
@@ -107,7 +106,7 @@ def test_virtual_file_bad_direction():
107106
)
108107
with pytest.raises(GMTInvalidInput):
109108
with lib.open_virtual_file(*vfargs):
110-
print("This should have failed")
109+
pass
111110

112111

113112
@pytest.mark.parametrize(
@@ -280,7 +279,7 @@ def test_virtualfile_from_vectors_diff_size():
280279
with clib.Session() as lib:
281280
with pytest.raises(GMTInvalidInput):
282281
with lib.virtualfile_from_vectors(x, y):
283-
print("This should have failed")
282+
pass
284283

285284

286285
def test_virtualfile_from_matrix(dtypes):

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ select = [
120120
"RSE", # flake8-raise
121121
"S", # flake8-bandit
122122
"SIM", # flake8-simplify
123+
"T20", # flake8-print
123124
"TCH", # flake8-type-checking
124125
"TID", # flake8-tidy-imports
125126
"UP", # pyupgrade
@@ -141,6 +142,7 @@ known-third-party = ["pygmt"]
141142
[tool.ruff.lint.per-file-ignores]
142143
"__init__.py" = ["F401"] # Ignore `F401` (unused-import) in all `__init__.py` files
143144
"*/tests/test_*.py" = ["S101"] # Ignore `S101` (use of assert) in all tests files
145+
"examples/**/*.py" = ["T201"] # Allow `print` in examples
144146

145147
[tool.ruff.lint.pycodestyle]
146148
max-doc-length = 79

0 commit comments

Comments
 (0)