Skip to content

nitypes: Delete _typing submodule and use typing_extensions directly #21

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

Merged
merged 6 commits into from
May 6, 2025

Conversation

bkeryan
Copy link
Collaborator

@bkeryan bkeryan commented May 5, 2025

What does this Pull Request accomplish?

Add a dependency on the typing-extensions package and import symbols directly from typing_extensions.

Why should this Pull Request be merged?

Single-sourcing typing_extensions imports in a private _typing submodule is not working well. I'm starting to think that avoiding typing_extensions at run time is not worth it. It is lightweight and has no external dependencies.

With a private _typing submodule, sphinx-autoapi renders type aliases as nitypes._typing.TypeAlias. If we use typing.TypeAlias directly, it renders them as a PEP 695 type statement showing what they are aliased to. I have proposed updating sphinx-autoapi to do the same for typing_extensions.TypeAlias: readthedocs/sphinx-autoapi#521

This pattern works for sphinx-autoapi, but not for mypy, due to python/mypy#14220

try:
    from typing import TypeAlias
except ImportError:
    from typing_extensions import TypeAlias  # or from nitypes._typing

What testing has been done?

Ran nps, mypy, pytest.
Generated docs with readthedocs/sphinx-autoapi#521 and verified that type aliases are rendered properly.

@bkeryan bkeryan requested a review from csjall as a code owner May 5, 2025 23:15
Copy link

github-actions bot commented May 5, 2025

Test Results

   10 files  ±0     10 suites  ±0   25s ⏱️ -1s
  511 tests ±0    511 ✅ ±0  0 💤 ±0  0 ❌ ±0 
5 110 runs  ±0  5 110 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit ec163ae. ± Comparison against base commit 10bdfbe.

@bkeryan bkeryan merged commit e8cbf0d into main May 6, 2025
14 checks passed
@bkeryan bkeryan deleted the users/bkeryan/just-use-typing-extensions branch May 6, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants