@@ -87,47 +87,54 @@ earlier Python versions), the :attr:`~annotationlib.Format.FORWARDREF` format
8787(which replaces undefined names with special markers), and the
8888:attr: `~annotationlib.Format.SOURCE ` format (which returns annotations as strings).
8989
90- This example shows how these formats behave::
91- 
92-    from annotationlib import get_annotations, Format 
93- 
94-    def func(arg: Undefined): 
95-        pass 
96- 
97-    print(get_annotations(func, format=Format.VALUE))  # raises NameError 
98-    print(get_annotations(func, format=Format.FORWARDREF))  # {'arg': ForwardRef('Undefined')} 
99-    print(get_annotations(func, format=Format.SOURCE))  # {'arg': 'Undefined'} 
90+ This example shows how these formats behave:
91+ 
92+ .. doctest ::
93+ 
94+    >>> from  annotationlib import  get_annotations, Format
95+    >>> def  func (arg : Undefined):
96+    ...     pass 
97+    >>> get_annotations(func, format = Format.VALUE ) 
98+    Traceback (most recent call last): 
99+      ...
100+    NameError: name 'Undefined' is not defined 
101+    >>> get_annotations(func, format = Format.FORWARDREF ) 
102+    {'arg': ForwardRef('Undefined')} 
103+    >>> get_annotations(func, format = Format.SOURCE ) 
104+    {'arg': 'Undefined'} 
100105
101106Implications if you write annotations in your code
102107^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
103108
104- If you write  annotations in your code (for example, for use with a static type
109+ If you define  annotations in your code (for example, for use with a static type
105110checker), then this change probably does not affect you: you can keep
106- writing annotations the same way you did in  previous versions of Python.
111+ writing annotations the same way you did with  previous versions of Python.
107112
108113You will likely be able to remove quoted strings in annotations, which are frequently
109114used for forward references. Similarly, if you use ``from __future__ import annotations ``
110115to avoid having to write strings in annotations, you may well be able to
111- remove it. However, if you rely on third-party libraries that read annotations,
112- those libraries may need changes to support unquoted annotations.
116+ remove that import. However, if you rely on third-party libraries that read annotations,
117+ those libraries may need changes to support unquoted annotations before they
118+ work as expected.
113119
114- Implications if you read  ``__annotations__ ``
115- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
120+ Implications for readers of  ``__annotations__ ``
121+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
116122
117123If your code reads the ``__annotations__ `` attribute on objects, you may want
118124to make changes in order to support code that relies on deferred evaluation of
119- annotations. For example, you may want to use the  :func: `annotationlib.get_annotations `
125+ annotations. For example, you may want to use :func: `annotationlib.get_annotations `
120126with the :attr: `~annotationlib.Format.FORWARDREF ` format, as the :mod: `dataclasses `
121127module now does.
122128
123129Related changes
124130^^^^^^^^^^^^^^^ 
125131
126- The changes in Python 3.14 are designed to minimize changes to code that contains
132+ The changes in Python 3.14 are designed to rework how ``__annotations__ ``
133+ works at runtime while minimizing breakage to code that contains
127134annotations in source code and to code that reads ``__annotations__ ``. However,
128- there are many changes to the supporting code, and if you rely  on undocumented 
129- details of  the annotation behavior or on private functions  in the standard library, 
130- your code may  not work in Python 3.14. To safeguard your code against future changes,
135+ if you rely on undocumented details of the annotation behavior or  on private 
136+ functions in  the standard library, there are many ways  in which your code may 
137+ not work in Python 3.14. To safeguard your code against future changes,
131138use only the documented functionality of the :mod: `annotationlib ` module.
132139
133140``from __future__ import annotations ``
@@ -137,9 +144,9 @@ In Python 3.7, :pep:`563` introduced the ``from __future__ import annotations``
137144directive, which turns all annotations into strings. This directive is now
138145considered deprecated and it is expected to be removed in a future version of Python.
139146However, this removal will not happen until after Python 3.13, the last version of
140- Python without deferred evaluation of annotations, loses support .
147+ Python without deferred evaluation of annotations, reaches its end of life .
141148In Python 3.14, the behavior of code using ``from __future__ import annotations ``
142- does not change .
149+ is unchanged .
143150
144151
145152Improved Error Messages
0 commit comments