Skip to content

clib.Session.virtualfile_in: Refactor if-else statements into match-case statements - #3521

Merged
seisman merged 1 commit into
mainfrom
refactor/virtualfile_in-cases
Oct 16, 2024
Merged

clib.Session.virtualfile_in: Refactor if-else statements into match-case statements#3521
seisman merged 1 commit into
mainfrom
refactor/virtualfile_in-cases

Conversation

@seisman

Copy link
Copy Markdown
Member

Description of proposed changes

This is another refactor about virtualfile_in after PR #3482 and PR #3351. This PR converts the if-else statements into match-case statements.

@seismanseisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. labels Oct 16, 2024
@seismanseisman added this to the 0.14.0 milestone Oct 16, 2024
Comment threadpygmt/clib/session.py
# Ensure the data is an iterable (Python list or tuple).
match kind:
case "arg" | "file" | "geojson" | "grid" | "image" | "stringio":
_data = (data,)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_data = (data,) if not isinstance(data, pathlib.PurePath) else (str(data),) is changed to _data = (data,).

For reference, the code str(data) was initially added in #1382 to support passing pathlib.Path as filenames. It turns out it's no longer necessary because the build_arg_list function already handle with pathlib.Path objects correctly:

ifinfile: # infile can be a single file or a list of files
ifisinstance(infile, str|pathlib.PurePath):
gmt_args= [str(infile), *gmt_args]
else:
gmt_args= [str(_file) for_fileininfile] +gmt_args
.

The support of pathlib.Path objects can even be tracked back to the old, deprecated build_arg_string function (xref: #1837).

We already have a lot of tests that takes a pathlib.Path object as input (e.g.,

deftest_info():
). So the changes should be safe if all tests pass.

@seismanseisman removed the needs review This PR has higher priority and needs review. label Oct 16, 2024
@seisman
seisman marked this pull request as draft October 16, 2024 02:42
@seisman
seisman marked this pull request as ready for review October 16, 2024 02:51
@seismanseisman added the needs review This PR has higher priority and needs review. label Oct 16, 2024
@seisman
seisman merged commit 9c47b38 into mainOct 16, 2024
@seisman
seisman deleted the refactor/virtualfile_in-cases branch October 16, 2024 03:01
@seismanseisman removed the needs review This PR has higher priority and needs review. label Oct 16, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenanceBoring but important stuff for the core devsskip-changelogSkip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@seisman@weiji14