@@ -172,30 +172,38 @@ Classes
172
172
:class: `~ForwardRef `. The string may not be exactly equivalent
173
173
to the original source.
174
174
175
- .. method :: evaluate(*, globals =None, locals =None, type_params =None, owner =None)
175
+ .. method :: evaluate(*, owner =None, globals =None, locals =None, type_params =None)
176
176
177
177
Evaluate the forward reference, returning its value.
178
178
179
179
This may throw an exception, such as :exc: `NameError `, if the forward
180
- reference refers to names that do not exist . The arguments to this
180
+ reference refers to a name that cannot be resolved . The arguments to this
181
181
method can be used to provide bindings for names that would otherwise
182
182
be undefined.
183
183
184
+ The *owner * parameter provides the preferred mechanism for passing scope
185
+ information to this method. The owner of a :class: `~ForwardRef ` is the
186
+ object that contains the annotation from which the :class: `~ForwardRef `
187
+ derives, such as a module object, type object, or function object.
188
+
189
+ The *globals *, *locals *, and *type_params * parameters provide a more precise
190
+ mechanism for influencing the names that are available when the :class: `~ForwardRef `
191
+ is evaluated. *globals * and *locals * are passed to :func: `eval `, representing
192
+ the global and local namespaces in which the name is evaluated.
193
+ The *type_params * parameter is relevant for objects created using the native
194
+ syntax for :ref: `generic classes <generic-classes >` and :ref: `functions <generic-functions >`.
195
+ It is a tuple of :ref: `type parameters <type-params >` that are in scope
196
+ while the forward reference is being evaluated. For example, if evaluating a
197
+ :class: `~ForwardRef ` retrieved from an annotation found in the class namespace
198
+ of a generic class ``C ``, *type_params * should be set to ``C.__type_params__ ``.
199
+
184
200
:class: `~ForwardRef ` instances returned by :func: `get_annotations `
185
201
retain references to information about the scope they originated from,
186
202
so calling this method with no further arguments may be sufficient to
187
203
evaluate such objects. :class: `~ForwardRef ` instances created by other
188
204
means may not have any information about their scope, so passing
189
205
arguments to this method may be necessary to evaluate them successfully.
190
206
191
- *globals * and *locals * are passed to :func: `eval `, representing
192
- the global and local namespaces in which the name is evaluated.
193
- *type_params *, if given, must be a tuple of
194
- :ref: `type parameters <type-params >` that are in scope while the forward
195
- reference is being evaluated. *owner * is the object that owns the
196
- annotation from which the forward reference derives, usually a function,
197
- class, or module.
198
-
199
207
.. important ::
200
208
201
209
Once a :class: `~ForwardRef ` instance has been evaluated, it caches
0 commit comments