Skip to content

Commit 15506ae

Browse files
authored
Remove dummy_context and use contextlib.nullcontext instead (#2491)
1 parent d2b0c39 commit 15506ae

File tree

4 files changed

+4
-34
lines changed

4 files changed

+4
-34
lines changed

pygmt/clib/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
import ctypes as ctp
88
import sys
9-
from contextlib import contextmanager
9+
from contextlib import contextmanager, nullcontext
1010

1111
import numpy as np
1212
import pandas as pd
@@ -25,7 +25,7 @@
2525
GMTInvalidInput,
2626
GMTVersionError,
2727
)
28-
from pygmt.helpers import data_kind, dummy_context, fmt_docstring, tempfile_from_geojson
28+
from pygmt.helpers import data_kind, fmt_docstring, tempfile_from_geojson
2929

3030
FAMILIES = [
3131
"GMT_IS_DATASET", # Entity is a data table
@@ -1451,7 +1451,7 @@ def virtualfile_from_data(
14511451

14521452
# Decide which virtualfile_from_ function to use
14531453
_virtualfile_from = {
1454-
"file": dummy_context,
1454+
"file": nullcontext,
14551455
"geojson": tempfile_from_geojson,
14561456
"grid": self.virtualfile_from_grid,
14571457
# Note: virtualfile_from_matrix is not used because a matrix can be

pygmt/helpers/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
args_in_kwargs,
1313
build_arg_string,
1414
data_kind,
15-
dummy_context,
1615
is_nonstr_iter,
1716
launch_external_viewer,
1817
)

pygmt/helpers/utils.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import time
1010
import webbrowser
1111
from collections.abc import Iterable
12-
from contextlib import contextmanager
1312

1413
import xarray as xr
1514
from pygmt.exceptions import GMTInvalidInput
@@ -92,33 +91,6 @@ def data_kind(data, x=None, y=None, z=None, required_z=False):
9291
return kind
9392

9493

95-
@contextmanager
96-
def dummy_context(arg):
97-
"""
98-
Dummy context manager.
99-
100-
Does nothing when entering or exiting a ``with`` block and yields the
101-
argument passed to it.
102-
103-
Useful when you have a choice of context managers but need one that does
104-
nothing.
105-
106-
Parameters
107-
----------
108-
arg : anything
109-
The argument that will be returned by the context manager.
110-
111-
Examples
112-
--------
113-
114-
>>> with dummy_context("some argument") as temp:
115-
... print(temp)
116-
...
117-
some argument
118-
"""
119-
yield arg
120-
121-
12294
def build_arg_string(kwdict, confdict=None, infile=None, outfile=None):
12395
r"""
12496
Convert keyword dictionaries and input/output files into a GMT argument

pygmt/src/x2sys_cross.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
GMTTempFile,
1313
build_arg_string,
1414
data_kind,
15-
dummy_context,
1615
fmt_docstring,
1716
kwargs_to_strings,
1817
unique_name,
@@ -196,7 +195,7 @@ def x2sys_cross(tracks=None, outfile=None, **kwargs):
196195
for track in tracks:
197196
kind = data_kind(track)
198197
if kind == "file":
199-
file_contexts.append(dummy_context(track))
198+
file_contexts.append(contextlib.nullcontext(track))
200199
elif kind == "matrix":
201200
# find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from
202201
# $X2SYS_HOME/TAGNAME/TAGNAME.tag file

0 commit comments

Comments
 (0)