Skip to content

PEP 649: Change the defined format values to an IntEnum #3127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
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
16 changes: 10 additions & 6 deletions pep-0649.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this list also need updating?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you have in mind. The enum values are consistent between the two definitions, they're not out-of-date.

I'm gonna consider this "done", as in, there was no problem. If you still have feedback on this, please add it to the other PR, #3138. Thanks!

Expand Down Expand Up @@ -573,19 +574,19 @@ 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;
whitespace may be normalized, and constant values may
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.
Expand Down Expand Up @@ -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
```
Comment on lines 718 to +725
Copy link
Member

@AA-Turner AA-Turner Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax fix:

Suggested change
``inspect`` module::
```
class AnnotationFormat(enum.IntEnum):
VALUE = 1
FORWARDREF = 2
SOURCE = 3
```
``inspect`` module:
.. code:: python
class AnnotationFormat(enum.IntEnum):
VALUE = 1
FORWARDREF = 2
SOURCE = 3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (in other PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


The default value for the ``format`` parameter is ``1``,
which is ``VALUE`` format.
Expand All @@ -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
Comment on lines +734 to +735
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If now an enum, do these still make sense, as one could just iterate through the enum?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see a strong use case for these, so maybe we should just drop them. We can always re-add them in a later version if a good use case comes up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Iterating through the enum is an even better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(work is in other PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



Also, when either ``__annotations__`` or ``__annotate__`` is updated on an
Expand Down