python / python/cpython

Avoid eagerly evaluating annotations

Open
#132,493 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

There are various places in the stdlib where we access the .__annotations__ attribute. Under PEP-649 / PEP-749, this now forces evaluation of lazy annotations. We should avoid evaluating annotations where it is not necessary.

For example, currently typing.Protocol evaluates its annotations at protocol creation time.

Linked PRs
  • gh-132494
  • gh-132534
  • gh-132596
  • gh-133411
  • gh-133415
  • gh-133796

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked PRs and the stdlib sites that access .__annotations__, with typing.Protocol as the named example. Use PEP-649 and PEP-749 to understand the lazy-annotation behavior; done means unnecessary annotation evaluation is avoided, especially during protocol creation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.