]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-118761: Lazily import annotationlib in typing (#132060)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 4 Apr 2025 15:57:10 +0000 (08:57 -0700)
committerGitHub <noreply@github.com>
Fri, 4 Apr 2025 15:57:10 +0000 (08:57 -0700)
commit305be5fb1a1ece7f9651ae98053dbe79bf439aa4
tree8d5cc9e5b0a9b2d7c3fb5a8da2056cb0b572a774
parent04bc681e7cf5b7effd99e676b7deceb27fb34434
gh-118761: Lazily import annotationlib in typing (#132060)

annotationlib is used quite a few times in typing.py, but I think the
usages are just rare enough that this makes sense.

The import would get triggered by:
- Using get_type_hints(), evaluate_forward_ref(), and similar introspection
  functions
- Using a string annotation anywhere that goes through _type_convert (e.g.,
  "Final['x']" will trigger an annotationlib import in order to access the
  ForwardRef class).
- Creating a TypedDict or NamedTuple (unless it's empty or PEP 563 is on).

Lots of programs will want to use typing without any of these, so the tradeoff
seems worth it.
Lib/typing.py