This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: CO_FUTURE_ANNOTATIONS flag is not documented or in inspect
Type: Stage:
Components: Documentation, Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: BTaskaya, Mark.Shannon, benjamin.peterson, brett.cannon, docs@python, eric.araujo, pablogsal, saulshanabrook, yselivanov
Priority: normal Keywords:

Created on 2021-11-14 08:20 by saulshanabrook, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg406309 - (view) Author: Saul Shanabrook (saulshanabrook) * Date: 2021-11-14 08:20
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.
msg406310 - (view) Author: Saul Shanabrook (saulshanabrook) * Date: 2021-11-14 08:28
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.
msg406311 - (view) Author: Saul Shanabrook (saulshanabrook) * Date: 2021-11-14 08:35
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.
msg406621 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-11-19 22:07
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'
msg406622 - (view) Author: Saul Shanabrook (saulshanabrook) * Date: 2021-11-19 22:15
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?
msg406732 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-11-21 17:17
I am not sure.  Adding compiler people to the nosy list!
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89963
2021-11-21 17:18:11eric.araujosetstage: resolved ->
versions: + Python 3.11, - Python 3.7
2021-11-21 17:17:40eric.araujosetnosy: + brett.cannon, benjamin.peterson, Mark.Shannon, yselivanov, pablogsal, BTaskaya
messages: + msg406732
2021-11-19 22:15:08saulshanabrooksetmessages: + msg406622
2021-11-19 22:07:56eric.araujosetnosy: + eric.araujo
messages: + msg406621
2021-11-14 08:35:18saulshanabrooksetstatus: closed -> open

messages: + msg406311
2021-11-14 08:28:27saulshanabrooksetstatus: open -> closed

messages: + msg406310
stage: resolved
2021-11-14 08:20:37saulshanabrookcreate