Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

seisman
Copy link
Member

@seisman seisman commented Oct 16, 2024

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.

@seisman seisman 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
@seisman seisman added this to the 0.14.0 milestone Oct 16, 2024
# Ensure the data is an iterable (Python list or tuple).
match kind:
case "arg" | "file" | "geojson" | "grid" | "image" | "stringio":
_data = (data,)
Copy link
Member Author

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:

if infile: # infile can be a single file or a list of files
if isinstance(infile, str | pathlib.PurePath):
gmt_args = [str(infile), *gmt_args]
else:
gmt_args = [str(_file) for _file in infile] + 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.,

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

@seisman seisman 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
@seisman seisman added the needs review This PR has higher priority and needs review. label Oct 16, 2024
@seisman seisman merged commit 9c47b38 into main Oct 16, 2024
34 of 35 checks passed
@seisman seisman deleted the refactor/virtualfile_in-cases branch October 16, 2024 03:01
@seisman seisman removed the needs review This PR has higher priority and needs review. label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants