-
Notifications
You must be signed in to change notification settings - Fork 122
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 from __future__ import annotations
#962
Conversation
Codecov ReportBase: 90.09% // Head: 90.13% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #962 +/- ##
==========================================
+ Coverage 90.09% 90.13% +0.04%
==========================================
Files 47 47
Lines 6086 6111 +25
Branches 913 913
==========================================
+ Hits 5483 5508 +25
Misses 422 422
Partials 181 181
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
If we're worried about this, we could leave stubs for these names around for a bit that emit a warning if they're accessed. It seems that pystac-client at least is OK: https://github.com/stac-utils/pystac-client/search?q=Item_Type. With a module-level |
After playing some more, I think it's not worth worrying about. As a test, I tried to import So it appears there's decent guardrails in place already to ensure no one is using these "internal" type names. |
49984b0
to
79f3309
Compare
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 looks really good to me; much cleaner. __future__
to the rescue!
1814b74
to
5963b17
Compare
Related Issue(s):
Tl;dr:
Switch to using
from __future__ import annotations
to give us slightly cleaner type signatures.Description:
As described in the mypy documentation, there are three tools at our disposal when resolving runtime typing issues:
from __future__ import annotations
typing.TYPE_CHECKING
Currently, pystac uses string types and
typing.TYPE_CHECKING
. This works fine, but does lead to a bit of clutter in the typing namespace, e.g.:pystac/pystac/asset.py
Lines 8 to 11 in f44de3c
"Item_Type"
and friends work fine for the purposes of defining our type signatures, but (IMO) they feel like a workaround and are a little awkward. Additionally, names like"Item_Type"
will be confusing when combined with the names required to fix #862, e.g.:This PR removes the
*_Type
names, and usesfrom __future__ import annotations
throughout the library to simplify some type signatures. I don't believe this is a risky change, because (a) it's recommended by mypy as a potential solution to typing issues, and (b) this may become the default Python behavior in the future, in which case we're setting ourselves up for success later.There are no functional changes to behavior in this PR, this is purely a typing change. Also, because names like
Item_Type
are only used internally, I believe this PR is a non-breaking change.As a sidecar fix, I also removed two unused imports in the top-level
__init__.py
.PR Checklist:
pre-commit run --all-files
)scripts/test
)