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|VegetableclassAnimal:
passclassVegetable:
passassertAnimalOrVegetable.__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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gvanrossum
Awaiting requested review from gvanrossum
gvanrossum will be requested when the pull request is marked ready for review
gvanrossum is a code owner
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.