Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(git): undo extra changes from the last push use “git restore” com…
…mand

#132056 (comment)
Signed-off-by: Kristinita <Kristinita@users.noreply.github.com>
  • Loading branch information
Kristinita committed Apr 3, 2025
commit 6d29f258b6a4d0ad5066c9c932b1b87b8a62d807
28 changes: 10 additions & 18 deletions Doc/library/annotationlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,38 +172,30 @@ Classes
:class:`~ForwardRef`. The string may not be exactly equivalent
to the original source.

.. method:: evaluate(*, owner=None, globals=None, locals=None, type_params=None)
.. method:: evaluate(*, globals=None, locals=None, type_params=None, owner=None)

Evaluate the forward reference, returning its value.

This may throw an exception, such as :exc:`NameError`, if the forward
reference refers to a name that cannot be resolved. The arguments to this
reference refers to names that do not exist. The arguments to this
method can be used to provide bindings for names that would otherwise
be undefined.

The *owner* parameter provides the preferred mechanism for passing scope
information to this method. The owner of a :class:`~ForwardRef` is the
object that contains the annotation from which the :class:`~ForwardRef`
derives, such as a module object, type object, or function object.

The *globals*, *locals*, and *type_params* parameters provide a more precise
mechanism for influencing the names that are available when the :class:`~ForwardRef`
is evaluated. *globals* and *locals* are passed to :func:`eval`, representing
the global and local namespaces in which the name is evaluated.
The *type_params* parameter is relevant for objects created using the native
syntax for :ref:`generic classes <generic-classes>` and :ref:`functions <generic-functions>`.
It is a tuple of :ref:`type parameters <type-params>` that are in scope
while the forward reference is being evaluated. For example, if evaluating a
:class:`~ForwardRef` retrieved from an annotation found in the class namespace
of a generic class ``C``, *type_params* should be set to ``C.__type_params__``.

:class:`~ForwardRef` instances returned by :func:`get_annotations`
retain references to information about the scope they originated from,
so calling this method with no further arguments may be sufficient to
evaluate such objects. :class:`~ForwardRef` instances created by other
means may not have any information about their scope, so passing
arguments to this method may be necessary to evaluate them successfully.

*globals* and *locals* are passed to :func:`eval`, representing
the global and local namespaces in which the name is evaluated.
*type_params*, if given, must be a tuple of
:ref:`type parameters <type-params>` that are in scope while the forward
reference is being evaluated. *owner* is the object that owns the
annotation from which the forward reference derives, usually a function,
class, or module.

.. important::

Once a :class:`~ForwardRef` instance has been evaluated, it caches
Expand Down
12 changes: 10 additions & 2 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3466,8 +3466,16 @@ Introspection helpers
* Supports the :attr:`~annotationlib.Format.FORWARDREF` and
:attr:`~annotationlib.Format.STRING` formats.

See the documentation for :meth:`annotationlib.ForwardRef.evaluate` for
the meaning of the *owner*, *globals*, *locals*, and *type_params* parameters.
*forward_ref* must be an instance of :class:`~annotationlib.ForwardRef`.
*owner*, if given, should be the object that holds the annotations that
the forward reference derived from, such as a module, class object, or function.
It is used to infer the namespaces to use for looking up names.
*globals* and *locals* can also be explicitly given to provide
the global and local namespaces.
*type_params* is a tuple of :ref:`type parameters <type-params>` that
are in scope when evaluating the forward reference.
This parameter must be provided (though it may be an empty tuple) if *owner*
is not given and the forward reference does not already have an owner set.
*format* specifies the format of the annotation and is a member of
the :class:`annotationlib.Format` enum.

Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,15 @@ def compile_trampolines_for_all_functions():

def _is_perf_version_at_least(major, minor):
# The output of perf --version looks like "perf version 6.7-3" but
# it can also be perf version "perf version 5.15.143", or even include
# a commit hash in the version string, like "6.12.9.g242e6068fd5c"
# it can also be perf version "perf version 5.15.143"
try:
output = subprocess.check_output(["perf", "--version"], text=True)
except (subprocess.CalledProcessError, FileNotFoundError):
return False
version = output.split()[2]
version = version.split("-")[0]
version = version.split(".")
version = tuple(map(int, version[:2]))
version = tuple(map(int, version))
return version >= (major, minor)


Expand Down
15 changes: 14 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7311,7 +7311,20 @@ def test_evaluate_forward_ref(self):

def test_evaluate_forward_ref_no_type_params(self):
ref = ForwardRef('int')
self.assertIs(typing.evaluate_forward_ref(ref), int)
with self.assertWarnsRegex(
DeprecationWarning,
(
"Failing to pass a value to the 'type_params' parameter "
"of 'typing.evaluate_forward_ref' is deprecated, "
"as it leads to incorrect behaviour"
),
):
typing.evaluate_forward_ref(ref)

# No warnings when `type_params` is passed:
with warnings.catch_warnings(record=True) as w:
typing.evaluate_forward_ref(ref, type_params=())
self.assertEqual(w, [])


class CollectionsAbcTests(BaseTestCase):
Expand Down
7 changes: 5 additions & 2 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def evaluate_forward_ref(
owner=None,
globals=None,
locals=None,
type_params=None,
type_params=_sentinel,
format=annotationlib.Format.VALUE,
_recursive_guard=frozenset(),
):
Expand All @@ -963,12 +963,15 @@ def evaluate_forward_ref(
infer the namespaces to use for looking up names. *globals* and *locals*
can also be explicitly given to provide the global and local namespaces.
*type_params* is a tuple of type parameters that are in scope when
evaluating the forward reference. This parameter should be provided (though
evaluating the forward reference. This parameter must be provided (though
it may be an empty tuple) if *owner* is not given and the forward reference
does not already have an owner set. *format* specifies the format of the
annotation and is a member of the annotationlib.Format enum.

"""
if type_params is _sentinel:
_deprecation_warning_for_no_type_params_passed("typing.evaluate_forward_ref")
type_params = ()
if format == annotationlib.Format.STRING:
return forward_ref.__forward_arg__
if forward_ref.__forward_arg__ in _recursive_guard:
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/get_externals.bat
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ echo.Fetching external binaries...

set binaries=
if NOT "%IncludeLibffi%"=="false" set binaries=%binaries% libffi-3.4.4
if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-3.0.16.2
if NOT "%IncludeSSL%"=="false" set binaries=%binaries% openssl-bin-3.0.16.1
if NOT "%IncludeTkinter%"=="false" set binaries=%binaries% tcltk-8.6.15.0
if NOT "%IncludeSSLSrc%"=="false" set binaries=%binaries% nasm-2.11.06

Expand Down
2 changes: 1 addition & 1 deletion PCbuild/python.props
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<libffiIncludeDir Condition="$(libffiIncludeDir) == ''">$(libffiOutDir)include</libffiIncludeDir>
<mpdecimalDir Condition="$(mpdecimalDir) == ''">$(ExternalsDir)\mpdecimal-4.0.0\</mpdecimalDir>
<opensslDir Condition="$(opensslDir) == ''">$(ExternalsDir)openssl-3.0.16\</opensslDir>
<opensslOutDir Condition="$(opensslOutDir) == ''">$(ExternalsDir)openssl-bin-3.0.16.2\$(ArchName)\</opensslOutDir>
<opensslOutDir Condition="$(opensslOutDir) == ''">$(ExternalsDir)openssl-bin-3.0.16.1\$(ArchName)\</opensslOutDir>
<opensslIncludeDir Condition="$(opensslIncludeDir) == ''">$(opensslOutDir)include</opensslIncludeDir>
<nasmDir Condition="$(nasmDir) == ''">$(ExternalsDir)\nasm-2.11.06\</nasmDir>
<zlibDir Condition="$(zlibDir) == ''">$(ExternalsDir)\zlib-1.3.1\</zlibDir>
Expand Down
Loading