Skip to content

Commit

Permalink
PEP 749: Add annotations_to_source, value_to_source (#3998)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Sep 25, 2024
1 parent d135546 commit 6fe0175
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions peps/pep-0749.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ The module will contain the following functionality:
dictionary. This is intended to be used for evaluating deferred attributes introduced by
:pep:`695` and :pep:`696`; see below for details. *func* may be ``None``
for convenience; if ``None`` is passed, the function also returns ``None``.
* ``annotations_to_source(annotations: dict[str, object]) -> dict[str, str]``: a function that
converts each value in an annotations dictionary to a string representation.
This is useful for
implementing the ``SOURCE`` format in cases where the original source is not available,
such as in the functional syntax for :py:class:`typing.TypedDict`.
* ``value_to_source(value: object) -> str``: a function that converts a single value to a
string representation. This is used by ``annotations_to_source``.
It uses ``repr()`` for most values, but for types it returns the fully qualified name.
It is also useful as a helper for the ``repr()`` of a number of objects in the
:py:mod:`typing` and :py:mod:`collections.abc` modules.

A new function is also added to the :py:mod:`!typing` module, ``typing.evaluate_forward_ref``.
This function is a wrapper around the ``ForwardRef.evaluate`` method, but it performs
Expand Down

0 comments on commit 6fe0175

Please sign in to comment.