Skip to content

pyrepl always has from __future__ import annotations on #119443

Closed

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

Activity

  1. added
    type-bug
    3.13
    3.14
    topic-repl
    on May 22, 2024
  2. added a commit that references this issue on May 24, 2024
  3. JelleZijlstra commented on May 24, 2024

    @JelleZijlstra
    MemberAuthor

    There's a related issue where it is impossible to turn a future import on in the REPL, because every line is compiled separately, and the future imports from the previous one are forgotten when the next one runs.

  4. added 2 commits that reference this issue on May 24, 2024
  5. added a commit that references this issue on May 29, 2024
  6. added a commit that references this issue on May 29, 2024
  7. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.133.14topic-repltype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions