This PR contains a subset of changes in PR #3326. I open this PR so that PR #3326 can be smaller and easier for review.
This PR refactors the following codes:
with Session() as lib:
if spec is None:
specfile = ""
elif data_kind(spec) == "file" and not is_nonstr_iter(spec):
# Is a file but not a list of files
specfile = spec
else:
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
lib.call_module(module="legend", args=build_arg_list(kwargs, infile=specfile))
to
kind = data_kind(spec)
if kind not in {"vectors", "file"}: # kind="vectors" means spec is None
raise GMTInvalidInput(f"Unrecognized data type: {type(spec)}")
if kind == "file" and is_nonstr_iter(spec):
raise GMTInvalidInput("Only one legend specification file is allowed.")
with Session() as lib:
lib.call_module(module="legend", args=build_arg_list(kwargs, infile=spec))
The pros are:
Raise exceptions if any before entering a session
Better error message if multiple legend files are given
Description of proposed changes
This PR contains a subset of changes in PR #3326. I open this PR so that PR #3326 can be smaller and easier for review.
This PR refactors the following codes:
to
The pros are: