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

Partially typecheck APIformatting module #598

Open
wants to merge 7 commits into
base: development
Choose a base branch
from

Conversation

mfisher87
Copy link
Member

Important

To be merged only after merging #593 and then rebasing

Add type annotations and some refactors to the APIformatting module.

Copy link

github-actions bot commented Sep 5, 2024

Binder 👈 Launch a binder notebook on this branch for commit 79fccf1

I will automatically update this comment whenever this PR is modified

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

Binder 👈 Launch a binder notebook on this branch for commit 3da94ef

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 54.54545% with 10 lines in your changes missing coverage. Please review.

Project coverage is 65.44%. Comparing base (1606dd0) to head (3da94ef).

Files with missing lines Patch % Lines
icepyx/core/APIformatting.py 54.54% 5 Missing and 5 partials ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           development     #598      +/-   ##
===============================================
- Coverage        65.66%   65.44%   -0.23%     
===============================================
  Files               38       38              
  Lines             3122     3128       +6     
  Branches           599      601       +2     
===============================================
- Hits              2050     2047       -3     
- Misses             984      990       +6     
- Partials            88       91       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

assert key in [
"time",
"temporal",
], "An invalid time key was submitted for formatting."
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic (is key "time" or "temporal"?) is repeated just below, so I moved the error statement into that conditional.

In general, assertions should not be used in "the code" (use only in the tests) unless you specifically want the assertions to be controllable at runtime. python -O will disable all assertions like -W disables warnings. So when I moved this logic I also changed it to raise a RuntimeError.

@@ -282,31 +283,14 @@ def __init__(
self._fmted_keys = values if values is not None else {}

@property
def poss_keys(self):
def poss_keys(self) -> dict[str, list[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.

This property returns static data, from what I can tell, so I simplified it down, and removed _poss_keys attribute.

@@ -341,8 +325,17 @@ def _get_possible_keys(self) -> dict[str, list[str]]:
"Coverage",
],
}
else:
raise RuntimeError("Programmer error!")
Copy link
Member Author

@mfisher87 mfisher87 Sep 5, 2024

Choose a reason for hiding this comment

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

The typechecker doesn't seem to be good at knowing whether a conditional is "exhaustive", so we're making that explicit here. I used "Programmer error!" to indicate this is something a user should never see. We can create a new error class instead if that makes more sense!

@mfisher87 mfisher87 force-pushed the refactor-and-typecheck-api-interfaces branch from 18bd814 to a8996d1 Compare September 12, 2024 16:22
Base automatically changed from refactor-and-typecheck-api-interfaces to development September 17, 2024 23:48
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