Skip to content

change convention for typing_extensions#15870

Merged
mhvk merged 2 commits into
astropy:mainfrom
nstarman:infra-typing_extensions
Jan 12, 2024
Merged

change convention for typing_extensions#15870
mhvk merged 2 commits into
astropy:mainfrom
nstarman:infra-typing_extensions

Conversation

@nstarman
Copy link
Copy Markdown
Member

See #15867 for discussion!

In a recent #15686 it was noted that typing_extensions is not a runtime dependency and as is consistent with our current policy we added a version check. That was good!
Now that we're starting to add type annotations, and typing_extensions is an integral part of that effort I think it's worth formalizing how we deal with typing_extensions.

typing_extensions is developed within the core Python org (https://github.com/python/typing_extensions). It is effectively core python. Its mission is to provide backports of typing for use in earlier versions of Python. Internally typing_extensions does Python version checks to determine whether it should just re-export from typing or needs to define the official backport. ALL standard type checkers, like mypy, recognize typing_extensions since it is "core" python. Moreover, ruff has specific rules to automatically change our imports from typing_extensions to typing as we bump our minimum python version.

Putting all this together. Let's make our lives easier and reduce code clutter by trusting typing_extensions and our CI. We don't need to do manual Python version checks.
Let's make this our policy for typing_extensions!

Q: Why not make typing_extensions a runtime dependency?

Because we don't yet need it at runtime.

Q: is it really a lot of code clutter?

Heck yeah. This PR has one example. See also #15860 and #15853 (comment).
I suspect most files in Astropy will have this avoidable clutter.

@github-actions
Copy link
Copy Markdown
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approving.

Copy link
Copy Markdown
Member

@eerovaher eerovaher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that prevents importing from typing_extensions without the explicit version check is maintainer vigilance. Our CI doesn't help because if TYPE_CHECKING: blocks are not executed at runtime. These version checks are not something we should be burdening maintainers with.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jan 12, 2024

OK, two approvals, so let's get it in. Thanks, @nstarman!

@mhvk mhvk merged commit dcc4142 into astropy:main Jan 12, 2024
@nstarman nstarman deleted the infra-typing_extensions branch January 12, 2024 16:22
@eerovaher eerovaher mentioned this pull request Jan 15, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants