-
Notifications
You must be signed in to change notification settings - Fork 101
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
Use cached_property and types #1718
base: master
Are you sure you want to change the base?
Conversation
I am hoping that the type annotations improve the readthedocs build. ETA: looks like they do, at least to provide a list of attributes in a class, and to provide clickable types for arguments and return values. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1718 +/- ##
==========================================
+ Coverage 68.96% 69.09% +0.13%
==========================================
Files 105 105
Lines 24696 24729 +33
Branches 4409 4409
==========================================
+ Hits 17031 17087 +56
+ Misses 6560 6534 -26
- Partials 1105 1108 +3 ☔ View full report in Codecov by Sentry. |
src/pint/observatory/__init__.py
Outdated
@@ -428,17 +468,17 @@ def get_TDBs(self, t, method="default", ephem=None, options=None): | |||
else: | |||
raise ValueError(f"Unknown method '{method}'.") | |||
|
|||
def _get_TDB_default(self, t, ephem): | |||
def _get_TDB_default(self, t: astropy.time.Time, ephem): |
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.
does ephem
not get a type?
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 didn't add it because I wasn't sure what the type was. String I think?
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.
Yes, I think it's a string
src/pint/observatory/__init__.py
Outdated
return t.tdb | ||
|
||
def _get_TDB_ephem(self, t, ephem): | ||
def _get_TDB_ephem(self, t: astropy.time.Time, ephem): |
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.
Same for this instance.
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.
and later
src/pint/observatory/topo_obs.py
Outdated
@@ -277,11 +306,11 @@ def get_dict(self): | |||
return {self.name: output} | |||
|
|||
def get_json(self): |
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.
return type?
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 trying to apply incremental typing just to those functions I touched. But if we're going all in on type annotations then I can be more aggressive.
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.
ok, sure. either way.
src/pint/observatory/topo_obs.py
Outdated
return json.dumps(self.get_dict()) | ||
|
||
def separation(self, other, method="cartesian"): | ||
"""Return separation between two TopoObs objects | ||
def separation(self, other: "TopoObs", method: str = "cartesian"): |
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.
return type?
src/pint/observatory/topo_obs.py
Outdated
for clock in self._clock: | ||
t = min(t, clock.last_correction_mjd()) | ||
return t | ||
|
||
def _get_TDB_ephem(self, t, ephem): | ||
def _get_TDB_ephem(self, t: Time, ephem) -> Time: |
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.
type of ephem
?
@@ -389,8 +416,8 @@ def _get_TDB_ephem(self, t, ephem): | |||
# Topocenter to Geocenter | |||
# Since earth velocity is not going to change a lot in 3ms. The | |||
# differences between TT and TDB can be ignored. | |||
earth_pv = objPosVel_wrt_SSB("earth", t.tdb, ephem) | |||
obs_geocenter_pv = gcrs_posvel_from_itrf( | |||
earth_pv: PosVel = objPosVel_wrt_SSB("earth", t.tdb, ephem) |
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.
What is the advantage to typing of this sort? Is this to prevent any changes to the API?
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 tells the type checker to signal a problem if the function does not actually return a PosVel, or if the surrounding code uses the value in a way incompatible with a PosVel. More, it informs the reader what type this has, in case they don't know off the top of their head what type to expect. In this case it seemed useful because I wasn't ready to go digging about and annotate those two functions.
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.
ok, that makes sense.
Addresses part of #1708 and also demonstrates gradual typing towards #1709. Unsure whether this resolves the first.