Skip to content

Simplify typing.evaluate_forward_ref #133960

Closed

Description

@JelleZijlstra

Bug report

In PEP-749 I added typing.evaluate_forward_ref to replace the private typing.ForwardRef._evaluate, which is being used by some external users.

The current documentation claims these differences from annotationlib.ForwardRef.evaluate:

  1. Recursively evaluates forward references nested within the type hint.
  2. Raises TypeError when it encounters certain objects that are not valid type hints.
  3. Replaces type hints that evaluate to None with types.NoneType.
  4. Supports the FORWARDREF and STRING formats.

(1) is useful and fits well with the typing module; annotationlib can't do this because it requires introspecting into typing-specific objects. (2) I feel is not useful (compare #133959): the type check is not particularly thorough, and it's generally better for callers to allow more objects through that callers can handle on their own terms. (3) is sort of harmless but not particularly useful. (4) is not true any more since I also added support for these formats to ForwardRef.evaluate.

So I'd like to drop differences 2 through 4, leaving the function focused on recursively evaluating nested ForwardRefs.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.14bugs and security fixes
    3.15bugs and security fixes
    on May 13, 2025
  2. added a commit that references this issue on May 13, 2025
  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 15, 2025
  4. added a commit that references this issue on May 25, 2025
  5. added a commit that references this issue on May 25, 2025
  6. added a commit that references this issue on May 25, 2025
  7. added a commit that references this issue on Jul 12, 2025
  8. added a commit that references this issue on Aug 4, 2025
  9. added a commit that references this issue on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions