diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index f10ab72a19a..d80ac6f1ee9 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -6,7 +6,7 @@ """ import ctypes as ctp import sys -from contextlib import contextmanager +from contextlib import contextmanager, nullcontext import numpy as np import pandas as pd @@ -25,7 +25,7 @@ GMTInvalidInput, GMTVersionError, ) -from pygmt.helpers import data_kind, dummy_context, fmt_docstring, tempfile_from_geojson +from pygmt.helpers import data_kind, fmt_docstring, tempfile_from_geojson FAMILIES = [ "GMT_IS_DATASET", # Entity is a data table @@ -1451,7 +1451,7 @@ def virtualfile_from_data( # Decide which virtualfile_from_ function to use _virtualfile_from = { - "file": dummy_context, + "file": nullcontext, "geojson": tempfile_from_geojson, "grid": self.virtualfile_from_grid, # Note: virtualfile_from_matrix is not used because a matrix can be diff --git a/pygmt/helpers/__init__.py b/pygmt/helpers/__init__.py index 4b9c4051e80..efea2845cc7 100644 --- a/pygmt/helpers/__init__.py +++ b/pygmt/helpers/__init__.py @@ -12,7 +12,6 @@ args_in_kwargs, build_arg_string, data_kind, - dummy_context, is_nonstr_iter, launch_external_viewer, ) diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index d972513ff6d..a7092a7ea9b 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -9,7 +9,6 @@ import time import webbrowser from collections.abc import Iterable -from contextlib import contextmanager import xarray as xr from pygmt.exceptions import GMTInvalidInput @@ -92,33 +91,6 @@ def data_kind(data, x=None, y=None, z=None, required_z=False): return kind -@contextmanager -def dummy_context(arg): - """ - Dummy context manager. - - Does nothing when entering or exiting a ``with`` block and yields the - argument passed to it. - - Useful when you have a choice of context managers but need one that does - nothing. - - Parameters - ---------- - arg : anything - The argument that will be returned by the context manager. - - Examples - -------- - - >>> with dummy_context("some argument") as temp: - ... print(temp) - ... - some argument - """ - yield arg - - def build_arg_string(kwdict, confdict=None, infile=None, outfile=None): r""" Convert keyword dictionaries and input/output files into a GMT argument diff --git a/pygmt/src/x2sys_cross.py b/pygmt/src/x2sys_cross.py index 26987452bf9..beb02bc7e5c 100644 --- a/pygmt/src/x2sys_cross.py +++ b/pygmt/src/x2sys_cross.py @@ -12,7 +12,6 @@ GMTTempFile, build_arg_string, data_kind, - dummy_context, fmt_docstring, kwargs_to_strings, unique_name, @@ -196,7 +195,7 @@ def x2sys_cross(tracks=None, outfile=None, **kwargs): for track in tracks: kind = data_kind(track) if kind == "file": - file_contexts.append(dummy_context(track)) + file_contexts.append(contextlib.nullcontext(track)) elif kind == "matrix": # find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from # $X2SYS_HOME/TAGNAME/TAGNAME.tag file