Skip to content

pyrepl always has from __future__ import annotations on #119443

Closed
@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

 % ./python.exe 
Python 3.14.0a0 (heads/main:e12a6780bb, May 22 2024, 13:54:40) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(x: y): pass
... 
>>> f.__annotations__
{'x': 'y'}

This likely happens because the code is exec()'ed in a file that has the future import; exec() inherits the __future__ state from the file where it's called (a questionable feature but that's how it is).

For what it's worth, PEP 649 explicitly says the REPL should continue to use "stock" semantics: https://peps.python.org/pep-0649/#interactive-repl-shell.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

### Tasks

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions