Skip to content

PEP 695: Use an unquoted forward reference in the type alias example - #5153

Draft
adamtheturtle wants to merge 1 commit into
python:mainfrom
adamtheturtle:docs/pep695-unquoted-forward-reference
Draft

adamtheturtle wants to merge 1 commit into
python:mainfrom
adamtheturtle:docs/pep695-unquoted-forward-reference

Conversation

@adamtheturtle

Copy link
Copy Markdown

The forward-reference example quotes Vegetable inside a | union. When the alias value is evaluated with ordinary classes, Animal | "Vegetable" raises TypeError. Use the unquoted name and link to the existing lazy-evaluation explanation so the example also works when inspected at runtime.

This clarifies the example without changing the specified semantics. For example, this succeeds on CPython 3.12 through 3.15:

type AnimalOrVegetable = Animal | Vegetable

class Animal:
    pass

class Vegetable:
    pass

assert AnimalOrVegetable.__value__ == Animal | Vegetable

Validation: the example passes on CPython 3.12.12, 3.13.13, 3.14.4, 3.14.7, and 3.15.0rc2. All pre-commit checks applicable to peps/pep-0695.rst pass. Generated the HTML and verified the updated example and local Lazy Evaluation link. The strict Sphinx build reports warnings because all six docs.python.org inventories return HTTP 503, leaving existing external cross-references unresolved.

  • Change is either:
    • To a Draft PEP
    • To an Accepted or Final PEP, with Steering Council approval
    • To fix an editorial issue (markup, typo, link, header, etc)
  • PR title prefixed with PEP number (e.g. PEP 123: Summary of changes)

This branch has not been deployed

No deployments
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.

1 participant