Add typing module to IO#15916
Conversation
Describes PathLike and two flavors of file-like Signed-off-by: nstarman <[email protected]>
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
mhvk
left a comment
There was a problem hiding this comment.
I cannot really judge correctness here, but it certainly looks good. Would it make sense to annotate some actual pieces of code? E.g., fits.open (hdu.hudlist.fitsopen)? But also fine to do things in follow-up (feeling free to still change this; nice to get it in well before 6.1 so there is time to iterate if needed).
| if TYPE_CHECKING: | ||
| from typing import TypeAlias | ||
|
|
||
| _T_co = TypeVar("_T_co", covariant=True) |
There was a problem hiding this comment.
This part I really have no idea what is being done...
See #15917! |
| _T_co = TypeVar("_T_co", covariant=True) | ||
| _T_contra = TypeVar("_T_contra", contravariant=True) | ||
|
|
||
| PathLike: TypeAlias = Union[str, bytes, os.PathLike] |
There was a problem hiding this comment.
Is it a good idea to have a type called PathLike given that os.PathLike exists in the standard library?
There was a problem hiding this comment.
I based the hint off of https://docs.python.org/3/glossary.html#term-path-like-object
There was a problem hiding this comment.
It's quite annoying that Python made os.PathLike given that their own definition of path-like includes str and bytes.
There was a problem hiding this comment.
We can reconsider this if it ever becomes a problem.
There was a problem hiding this comment.
We have just started adding type annotations to astropy, so we might want to make big changes to them. If we are going to have public documentation about typing then there should be a warning somewhere that makes it clear that typing support in astropy is experimental and subject to change without notice.
Describes PathLike and two flavors of file-like