`type` statement and forward references

I’m adding type statement support to our tool. We use type information for automatic type conversion, and at the moment the type statement is not supported. My plan is to just unwrap the created type aliases so that the type conversion logic sees the underlying types, and possibly later preserve the original name for documentation purposes.

I got unwrapping working like this:

while instance(hint, TypeAliasType):
    try:
        hint = hint.__value__
    except Exception as err:
        raise DataError(f"Resolving type alias '{hint}' failed: {err}")

I also tested that it can handle cases like these as expected:

type ForwardRef = Simple
type Simple = int
type Params = list[int]
type Union = int | float
type Invalid = bad

All seems to work fine, but I want to make sure I’ve covered everything. I’ve read the docs related to the type statement to see have I missed something, and got confused by quoting used in this example from PEP 695:

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

I know quoting can be used to create forward references like def f(a: "SomeType"), but based on these examples quoting wouldn’t be needed in this context:

>>> type A = B
>>> type B = int
>>> A.__value__
B
>>> A.__value__.__value__
<class 'int'>

If quoting is used, values don’t seem to be resolved:

>>> type A = "B"
>>> type B = int
>>> A.__value__
'B'

My question is, is the example in the PEP invalid or is quoting like that actually allowed? If it is allowed, how can I resolve the value?

I believe this will just never be resolvable and is a bad example.

May be worth noting that from Python 3.14 you can also get the ForwardRef format from type aliases using annotationlib.call_evaluate_function, similar to how annotationlib.get_annotations is used to get ForwardRef annotations.

from annotationlib import call_evaluate_function, Format

class Animal:
    ...

type AnimalOrVegetable = Animal | Vegetable

resolved = call_evaluate_function(AnimalOrVegetable.evaluate_value, format=Format.FORWARDREF)

print(resolved)
ForwardRef('__main__.Animal | Vegetable')

Thanks! I guess my current code then handles everything needed. If not, users can submit bug reports. Not sure are old PEPs ever updated, but fixing that example would probably be a good idea.