Skip to content

Commit 6fe0175

Browse files
PEP 749: Add annotations_to_source, value_to_source (#3998)
1 parent d135546 commit 6fe0175

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

peps/pep-0749.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ The module will contain the following functionality:
221221
dictionary. This is intended to be used for evaluating deferred attributes introduced by
222222
:pep:`695` and :pep:`696`; see below for details. *func* may be ``None``
223223
for convenience; if ``None`` is passed, the function also returns ``None``.
224+
* ``annotations_to_source(annotations: dict[str, object]) -> dict[str, str]``: a function that
225+
converts each value in an annotations dictionary to a string representation.
226+
This is useful for
227+
implementing the ``SOURCE`` format in cases where the original source is not available,
228+
such as in the functional syntax for :py:class:`typing.TypedDict`.
229+
* ``value_to_source(value: object) -> str``: a function that converts a single value to a
230+
string representation. This is used by ``annotations_to_source``.
231+
It uses ``repr()`` for most values, but for types it returns the fully qualified name.
232+
It is also useful as a helper for the ``repr()`` of a number of objects in the
233+
:py:mod:`typing` and :py:mod:`collections.abc` modules.
224234

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

0 commit comments

Comments
 (0)