clib.Session.virtualfile_in: Refactor if-else statements into match-case statements#3521
Merged
clib.Session.virtualfile_in: Refactor if-else statements into match-case statements#3521
Conversation
seisman
commented
Oct 16, 2024
| # Ensure the data is an iterable (Python list or tuple). | ||
| match kind: | ||
| case "arg" | "file" | "geojson" | "grid" | "image" | "stringio": | ||
| _data = (data,) |
Member
Author
There was a problem hiding this comment.
_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:
Lines 516 to 520 in d41922c
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.,
pygmt/pygmt/tests/test_info.py
Line 20 in d41922c
weiji14
approved these changes
Oct 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
This is another refactor about
virtualfile_inafter PR #3482 and PR #3351. This PR converts theif-elsestatements into match-case statements.