-
Notifications
You must be signed in to change notification settings - Fork 107
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
Typecheck some API interfaces #593
Typecheck some API interfaces #593
Conversation
👈 Launch a binder notebook on this branch for commit 5d8c38f I will automatically update this comment whenever this PR is modified 👈 Launch a binder notebook on this branch for commit 599a40e 👈 Launch a binder notebook on this branch for commit 1299db1 👈 Launch a binder notebook on this branch for commit 4c8ec7b 👈 Launch a binder notebook on this branch for commit bf54226 👈 Launch a binder notebook on this branch for commit cb4c043 👈 Launch a binder notebook on this branch for commit cac9d1c 👈 Launch a binder notebook on this branch for commit 181099f 👈 Launch a binder notebook on this branch for commit e6e7fe2 👈 Launch a binder notebook on this branch for commit 0440fa9 👈 Launch a binder notebook on this branch for commit df78ca2 👈 Launch a binder notebook on this branch for commit 126d3fc 👈 Launch a binder notebook on this branch for commit ee70196 👈 Launch a binder notebook on this branch for commit 434c28a 👈 Launch a binder notebook on this branch for commit 2247b2c 👈 Launch a binder notebook on this branch for commit 18bd814 👈 Launch a binder notebook on this branch for commit a8996d1 👈 Launch a binder notebook on this branch for commit dfe4c09 👈 Launch a binder notebook on this branch for commit f23f5c2 👈 Launch a binder notebook on this branch for commit fddf23a 👈 Launch a binder notebook on this branch for commit e155a9b 👈 Launch a binder notebook on this branch for commit 51b3492 👈 Launch a binder notebook on this branch for commit 7f60849 👈 Launch a binder notebook on this branch for commit bb96a5f 👈 Launch a binder notebook on this branch for commit 4cb5956 👈 Launch a binder notebook on this branch for commit 7a423a8 👈 Launch a binder notebook on this branch for commit 6a4acd9 👈 Launch a binder notebook on this branch for commit e41aed0 👈 Launch a binder notebook on this branch for commit 81d60dd |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## development #593 +/- ##
===============================================
- Coverage 71.60% 65.66% -5.95%
===============================================
Files 37 38 +1
Lines 3064 3122 +58
Branches 596 599 +3
===============================================
- Hits 2194 2050 -144
- Misses 766 984 +218
+ Partials 104 88 -16 ☔ View full report in Codecov by Sentry. |
1299db1
to
4c8ec7b
Compare
bf54226
to
cb4c043
Compare
2247b2c
to
18bd814
Compare
Co-Authored-By: Jessica Scheick <[email protected]>
Co-Authored-By: Jessica Scheick <[email protected]>
18bd814
to
a8996d1
Compare
f23f5c2
to
fddf23a
Compare
icepyx/core/granules.py
Outdated
CMRparams, | ||
reqparams, | ||
CMRparams: CMRParams, | ||
reqparams: EGISpecificParamsSearch, |
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.
reqparams: EGISpecificParamsSearch, | |
reqparams: EGISpecificParamsDownload, |
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.
is Query.reqparams
always of type EGISpecificParamsDownload
? Or only sometimes (this is my understanding)?
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.
I think this is probably the wrong way to handle things. We're telling the typechecker "Ignore your eyes and ears, just trust us" with the cast()
call. Instead, we can add a "typeguard" which is a runtime check that asserts a narrower type, e.g. a literal assert isinstance(...)
or if isinstance(...): raise
. I am hesitant to add runtime checks without fully grokking the code, but perhaps we do know for sure that reqparams
is always EGISpecificParamsDownload
at the point we're cast()
ing.
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.
is
Query.reqparams
always of typeEGISpecificParamsDownload
? Or only sometimes (this is my understanding)?
The latter - it's only sometimes of type EGISpecificParamsDownload
(when Query._reqparams._reqtype == "download"
). Otherwise it's of type "search", which maps to our EGIRequiredParamsSearch
.
but perhaps we do know for sure that reqparams is always EGISpecificParamsDownload at the point we're cast()ing.
I think this is true.
Co-authored-by: Jessica Scheick <[email protected]>
Excludes CMR typeddicts which contain symbols in some keys.
Is this the right way to handle this? Perhaps we need a typeguard. Co-Authored-By: Jessica Scheick <[email protected]>
bb96a5f
to
4cb5956
Compare
Co-authored-by: Jessica Scheick <[email protected]>
CMRparams, | ||
reqparams, | ||
CMRparams: CMRParams, | ||
reqparams: EGIRequiredParamsDownload, | ||
subsetparams, |
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.
subsetparams, | |
subsetparams: Union[EGIRequiredParamsSubset, dict[Never, Never]], |
I might have the syntax wrong. In some cases we specify the type from types.py
, and in others from APIformatting.py
(e.g. in query.py
).
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.
dict[Never, Never]
means an empty dict, and this change doesn't pass type checking. In what case would reqparams={}
be passed?
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.
I was simply adding a type for subsetparams, since it wasn't specified. It sounds like it would need to be something more like Optional[EGIRequiredParamsSubset]
so it doesn't otherwise require an empty dict.
In what case would reqparams={} be passed?
dict[Never, Never]
is not being specified as a valid type to reqparams
.
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.
Woops, I meant subsetparams
:)
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.
Approving this for merging now that we've released the last of v1 (v1.3.0). I think we've worked out most of the kinks and figure any others will be ironed out as we continue moving towards the refactor in v2. I'll be on PTO Tuesday and I know in our discussion today you said this was a critical next step for you for making progress.
Thanks, @JessicaS11 ! |
I'm going to be changing a lot in the refactor to use Harmony. The typechecker is going to help find sneaky bugs along the way. This is a start, but I'd really like feedback.
My main goal here is to avoid refactoring the code more than needed and set the stage for future cleanups and refactors. E.g. I think long-term, we will want to split up the
Parameters
class instead of having it handle all the kinds of parameters.I'm using pyright here for the first time, and I'm pleased with it compared to Mypy so far. The reason I switched to Pyright: python/mypy#12098