Refactor umm dict accessors - #1073
Conversation
00c8aad to
a4b5946
Compare
owenlittlejohns
left a comment
There was a problem hiding this comment.
I love this clean-up! I'm a big fan of dict.get('key') over dict['key'].
I had two quick comments, but they are kind of out of scope just from me skimming the rest of the file. The landing_page one is likely not an improvement, so definitely feel free to ignore that one.
| return "" | ||
| return self["umm"].get("Abstract", "") | ||
|
|
||
| def landing_page(self) -> str: |
There was a problem hiding this comment.
Is it worth doing something with landing_page, too? It'll need to be a bit sneakier where there's a list involved, but maybe something like:
def landing_page(self) -> str:
return next(iter(collection_results[0]._filter_related_links("LANDING PAGE")), "")
That might not be as readable, though, so feel free to ignore.
There was a problem hiding this comment.
I think this is a little harder to reason about the fallback value, at least for me.
I think the most readable form might actually be:
return links[0] if len(links) > 0 else ""There was a problem hiding this comment.
Got to love a good ternary. That works for me.
| return "" | ||
| return self["umm"].get("Abstract", "") | ||
|
|
||
| def landing_page(self) -> str: |
There was a problem hiding this comment.
Got to love a good ternary. That works for me.
This is a small PR to refactor
dictaccess so that instad of doing an upfront check for key existance and then accessing it, we use the built in.getmethod to handle this.I don't see any value in adding such a minor refactor to the changelog, so I have not updated it, but would be happy to if people feel otherswise.
Pull Request (PR) draft checklist - click to expand
contributing documentation
before getting started.
title such as "Add testing details to the contributor section of the README".
Example PRs: #763
example
closes #1. SeeGitHub docs - Linking a pull request to an issue.
CHANGELOG.mdwith details about your change in a section titled## Unreleased. If such a section does not exist, please create one. FollowCommon Changelog for your additions.
Example PRs: #763
README.mdwith details of changes to theearthaccess interface, if any. Consider new environment variables, function names,
decorators, etc.
Click the "Ready for review" button at the bottom of the "Conversation" tab in GitHub
once these requirements are fulfilled. Don't worry if you see any test failures in
GitHub at this point!
Pull Request (PR) merge checklist - click to expand
Please do your best to complete these requirements! If you need help with any of these
requirements, you can ping the
@nsidc/earthaccess-supportteam in a comment and wewill help you out!
Request containing "pre-commit.ci autofix" to automate this.