Adds typehints to TimeRange properties returning astropy.time.Time#8614
Open
daraghhollman wants to merge 1 commit into
Open
Adds typehints to TimeRange properties returning astropy.time.Time#8614daraghhollman wants to merge 1 commit into
TimeRange properties returning astropy.time.Time#8614daraghhollman wants to merge 1 commit into
Conversation
…ime` objects Adds return typehints for `TimeRange.start`, `TimeRange.end`, and `TimeRange.center`, which all return `astropy.time.Time`. Because of the complex `__init__` method in `TimeRange`, some LSPs interpret the output of the above attributes as `None | Time`, which can lead to LSPs showing an error when accessing the attributes and methods within. e.g. for: `time_range.start.to_datetime()` 'error| "to_datetime" is not a known attribute of "None"' (The above output is from pyright) This commit makes no runtime changes.
TimeRange attributes returning astropy.time.TimeTimeRange properties returning astropy.time.Time
Cadair
requested changes
May 11, 2026
Member
Cadair
left a comment
There was a problem hiding this comment.
Hi,thanks for the PR.
Could you please remove the return type in the docstring, as we don't need that information in two places. Once you've done this please verify that the built documentation has correctly displayed the return type from the function annotation.
Thanks!!
Contributor
Author
|
Hi @Cadair, it seems the documentation relies on the docstring only. After removing the type from the docstring, i.e. going from: @property
def start(self) -> Time:
"""
Get the start time.
Returns
-------
`astropy.time.Time`
The start time.
"""
return self._t1to: @property
def start(self) -> Time:
"""
Get the start time.
Returns
-------
The start time.
"""
return self._t1the built docs don't show any type. See screenshots from It would seem the current framework doesn't interpret the type from hints? Or have I misinterpreted what you meant? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


PR Description
Adds return typehints for
TimeRange.start,TimeRange.end, andTimeRange.center, which all returnastropy.time.Time.Due to the way the
__init__method inTimeRangeis structured, LSPs may interpret the output of the above properties asNone | Time, which can show an error when accessing the attributes and methods within (however there are no issues at runtime).e.g. for:
From my testing,
TimeRange.centerdoesn't behave like this, however I added the hint for consistency with thestartandendproperties.These changes don't affect runtime behaviour, but makes the package easier to work with in practice.
AI Assistance Disclosure
AI tools were used for: