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

A collection of "low-hanging fruit" refactors #612

Open
wants to merge 10 commits into
base: typecheck-spatial
Choose a base branch
from

Conversation

mfisher87
Copy link
Member

@mfisher87 mfisher87 commented Sep 18, 2024

Important

To be merged only after merging #605 and rebasing

I'm happy to split this in to multiple PRs, but there's a lot of disparate changes here and I didn't want to flood the queue before showing you the whole pile. Let me know!

Copy link

github-actions bot commented Sep 18, 2024

Binder 👈 Launch a binder notebook on this branch for commit 91bd9a8

I will automatically update this comment whenever this PR is modified

Binder 👈 Launch a binder notebook on this branch for commit b75d000

@mfisher87 mfisher87 changed the title Low hanging refactors A collection of "low-hanging fruit" refactors Sep 18, 2024
"ATL23",
], error_msg
else:
if not isinstance(product, str):
Copy link
Member Author

Choose a reason for hiding this comment

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

I find the style of:

if not valid:
  raise ...

# main logic here

more readable than:

if valid:
  # main logic here
else:
  raise ...

@@ -330,13 +332,13 @@ def gt2spot(gt, sc_orient):
elif gr_lr == "r":
spot = 6

if "spot" not in locals():
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at locals() is a smell to me. I feel it may throw off some other code-readers.

if not hasattr(self, "_granules") or self._granules is None:
self._granules = Granules()

return self._granules
Copy link
Member Author

Choose a reason for hiding this comment

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

Looks to me like self.granules is static and could be set at init-time as a class attribute, but then we wouldn't get this awesome docstring. I changed the method to a cached_property to, IMO, get the best qualities of both.

if self._ext_type == "bounding_box":
cmr_extent = ",".join(map(str, self._spatial_ext))
if self.extent_type == "bounding_box":
return ",".join(map(str, self._spatial_ext))
Copy link
Member Author

Choose a reason for hiding this comment

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

When there's an assignment like this, that tells me that something may be done to this variable after the conditional ends. Instead, return tells the reader right away that nothing further will happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant