Skip to content
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

pyrepl always has from __future__ import annotations on #119443

Closed
JelleZijlstra opened this issue May 22, 2024 · 1 comment
Closed

pyrepl always has from __future__ import annotations on #119443

JelleZijlstra opened this issue May 22, 2024 · 1 comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 22, 2024

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

No tasks being tracked yet.

Linked PRs

@JelleZijlstra JelleZijlstra added type-bug An unexpected behavior, bug, or error 3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell labels May 22, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 24, 2024
@JelleZijlstra
Copy link
Member Author

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.

JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 24, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 29, 2024
JelleZijlstra added a commit that referenced this issue May 29, 2024
…GH-119493) (#119697)

gh-119443: Turn off from __future__ import annotations in REPL (GH-119493)
(cherry picked from commit a8e35e8)

Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant