Open f9e7a2ee-b641-456a-a5a2-df4439a7109f opened 2 years ago
The CO_FUTURE_ANNOTATIONS code flag was added in Python 3.7 I believe in this PR https://github.com/python/cpython/pull/4390.
However, it does not appear in dis's COMPILER_FLAG_NAMES map and so is not documented in inspect or pretty printed.
I believe the fix would be to add it to the dict in dis as well as document it in inspect.
I am closing this because, I realized I was unclear on whether the future flags end up as code flags. I thought we were just missing this one, but then realized that none of the other future flags are documented either.
I had found a flag that was not recognized, 0x1000000, and for some reason thought it was related to the future annotations import.
Actually, keeping this open.
I am still unclear if this is expected behavior or not, but I do notice that the dis module is unable to read the flag when the annotations future is imported.
For example dis.pretty_flags(compile("from __future__ import annotations", "", "exec").co_flags)
return 'NOFREE, 0x1000000'
.
Sorry for the repeated messages.
No worry about posting multiple messages.
I think the flag is documented through the __future__ module. Future imports are both special-cased by the compiler to enable custom behaviour, but also real, regular imports!
>>> from __future__ import annotations
>>> annotations
_Feature((3, 7, 0, 'beta', 1), (3, 10, 0, 'alpha', 0), 16777216)
>>> hex(annotations.compiler_flag)
'0x1000000'
Thanks Éric!
Do you think it would make sense to add the future flags as well to the inspect flags documentation (https://docs.python.org/3/library/inspect.html#code-objects-bit-flags) and to the dis.pretty_flags?
I am not sure. Adding compiler people to the nosy list!
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['3.11', 'library', 'docs']
title = 'CO_FUTURE_ANNOTATIONS flag is not documented or in inspect'
updated_at =
user = 'https://github.com/saulshanabrook'
```
bugs.python.org fields:
```python
activity =
actor = 'eric.araujo'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation', 'Library (Lib)']
creation =
creator = 'saulshanabrook'
dependencies = []
files = []
hgrepos = []
issue_num = 45805
keywords = []
message_count = 6.0
messages = ['406309', '406310', '406311', '406621', '406622', '406732']
nosy_count = 9.0
nosy_names = ['brett.cannon', 'benjamin.peterson', 'eric.araujo', 'docs@python', 'Mark.Shannon', 'yselivanov', 'saulshanabrook', 'pablogsal', 'BTaskaya']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue45805'
versions = ['Python 3.11']
```