Skip to content

Conversation

paxnovem
Copy link
Contributor

@paxnovem paxnovem commented May 2, 2022

This PR reduces the time at startup that is taken at import time. This is achieved by delaying the evaluation of type imports.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@paxnovem paxnovem marked this pull request as ready for review May 2, 2022 21:27
@saroad2
Copy link
Contributor

saroad2 commented May 7, 2023

Since this PR was written, the PSF has decided to go on a different direction than from __future__ import annotations. You can read about it here. Right now they consider moving towards PEP 649 instead.

Unfortunately, I think we might should drop this PR. @davidism , would love to hear your opinion on it.

@davidism davidism added this to the 8.1.4 milestone Jun 30, 2023
@davidism
Copy link
Member

from __future__ import annotations will continue to work as it does, and any change will still result in deferred evaluation of annotations.

@davidism davidism modified the milestones: 8.1.4, 8.2.0 Jun 30, 2023
@davidism davidism force-pushed the import_perf_optimization branch from 72fd842 to ec258fe Compare August 20, 2023 18:43
@davidism
Copy link
Member

Updated to use modern typing syntax and features. Both MyPy and PyRight support using modern syntax with older Pythons when using from __future__ import annotations.

  • Remove typing_extensions where possible.
  • Use shorthand union syntax | instead of Union and Optional.
  • Use generic types from built-ins, collections, collections.abcandcontextlib`.
  • Quote TypeVar bound and cast types to avoid runtime evaluation of generics and unions.

@davidism davidism merged commit 56db546 into pallets:main Aug 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants