FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PEP 695: Use an unquoted forward reference in the type alias example by adamtheturtle · Pull Request #5153 · python/peps · GitHub

Repository navigation

Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 4 additions & 2 deletions peps/pep-0695.rst
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
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,14 @@ for type parameters.
type ListOrSet[T] = list[T] | set[T]


Type aliases can refer to themselves without the use of quotes.
Type aliases can refer to themselves and to names defined later without the use
of quotes. The value of a type alias is evaluated lazily (see `Lazy Evaluation`_),
so these names need not be defined when the alias is declared.

::

# A type alias that includes a forward reference
type AnimalOrVegetable = Animal | "Vegetable"
type AnimalOrVegetable = Animal | Vegetable

# A generic self-referential type alias
type RecursiveList[T] = T | list[RecursiveList[T]]
Expand Down
Loading

Back | FazBrowse Home | New Git URL