diff --git a/pep-0649.rst b/pep-0649.rst index 79fa999f4e5..3074678c95d 100644 --- a/pep-0649.rst +++ b/pep-0649.rst @@ -72,7 +72,8 @@ The functionality is accessed via a new keyword-only parameter, ``format``. ``format`` allows the user to request the annotations from these functions in a specific format. -Format identifiers are always predefined integer values. +Format identifiers are defined in the :mod:`inspect` module +in a new ``AnnotationFormat`` enum, which is an ``enum.IntEnum``. The formats defined by this PEP are: * ``inspect.VALUE = 1`` @@ -573,11 +574,11 @@ Language Reference: annotations values should be provided. Must be one of the following: - ``1`` (exported as ``inspect.VALUE``) + ``1`` (exported as ``inspect.AnnotationFormat.VALUE``) Values are the result of evaluating the annotation expressions. - ``2`` (exported as ``inspect.SOURCE``) + ``2`` (exported as ``inspect.AnnotationFormat.SOURCE``) Values are the text string of the annotation as it appears in the source code. May only be approximate; @@ -585,7 +586,7 @@ Language Reference: be optimized. It's possible the exact values of these strings could change in future version of Python. - ``3`` (exported as ``inspect.FORWARDREF``) + ``3`` (exported as ``inspect.AnnotationFormat.FORWARDREF``) Values are real annotation values (as per ``inspect.VALUE`` format) for defined values, and ``ForwardRef`` proxies for undefined values. @@ -716,9 +717,12 @@ annotations dict should be returned in. ``format`` accepts the following values, defined as attributes on the ``inspect`` module:: +``` +class AnnotationFormat(enum.IntEnum): VALUE = 1 FORWARDREF = 2 SOURCE = 3 +``` The default value for the ``format`` parameter is ``1``, which is ``VALUE`` format. @@ -727,8 +731,8 @@ The defined ``format`` values are guaranteed to be contiguous, and the ``inspect`` module also publishes attributes representing the minimum and maximum supported ``format`` values:: - FORMAT_MIN = VALUE - FORMAT_MAX = SOURCE + FORMAT_MIN = AnnotationFormat.VALUE + FORMAT_MAX = AnnotationFormat.SOURCE Also, when either ``__annotations__`` or ``__annotate__`` is updated on an