-
Notifications
You must be signed in to change notification settings - Fork 108
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
base: development
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. |
assert key in [ | ||
"time", | ||
"temporal", | ||
], "An invalid time key was submitted for formatting." |
There was a problem hiding this comment.
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
.
79fccf1
to
ca3f553
Compare
@@ -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]]: |
There was a problem hiding this comment.
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!") |
There was a problem hiding this comment.
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!
18bd814
to
a8996d1
Compare
ca3f553
to
3da94ef
Compare
Important
To be merged only after merging #593 and then rebasing
Add type annotations and some refactors to the APIformatting module.