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

barry_as_FLUFL future flag does not work in new REPL #124960

Open
sobolevn opened this issue Oct 4, 2024 · 8 comments
Open

barry_as_FLUFL future flag does not work in new REPL #124960

sobolevn opened this issue Oct 4, 2024 · 8 comments
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

@sobolevn
Copy link
Member

sobolevn commented Oct 4, 2024

Bug report

New REPL:

>>> from __future__ import barry_as_FLUFL
>>> 1 <> 2
  File "<python-input-1>", line 1
    1 <> 2
      ^^
SyntaxError: invalid syntax

Old REPL:

>>> from __future__ import barry_as_FLUFL
>>> 1 <> 2
True

I understand that this is just an easter egg :)

Linked PRs

@sobolevn sobolevn 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 Oct 4, 2024
@warsaw
Copy link
Member

warsaw commented Oct 4, 2024

Clearly this is a showstopper bug requiring @Yhg1s to delay Python 3.13.0 for another week and another RC! No respect for the FLUFL eh @pablogsal ??? 😭

@Yhg1s
Copy link
Member

Yhg1s commented Oct 4, 2024

I can't believe it, just last week @ambv and @pablogsal were complaining about how easter eggs were getting removed, and here they are, organising a coup! Clearly this should be fixed as soon as possible1!!!!

Footnotes

  1. which means 3.13.1

@nineteendo
Copy link
Contributor

Hmm, it looks like it's working in the commit that introduced the new REPL: f27f8c7

Screenshot 2024-10-05 at 21 52 09

@nineteendo
Copy link
Contributor

Bisected to a3e4fec.

@nineteendo
Copy link
Contributor

It's failing at this line:

tree = ast.parse(source)

@nineteendo
Copy link
Contributor

Note that this is equivalent to:

tree = compile(source, filename, symbol, ast.PyCF_ONLY_AST)

Which doesn't use codeop.Compile().

@nineteendo
Copy link
Contributor

Is this acceptable?

diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index d65b6d0d627..6e24860d3c8 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -83,7 +83,7 @@ def showtraceback(self):
 
     def runsource(self, source, filename="<input>", symbol="single"):
         try:
-            tree = ast.parse(source)
+            tree = self.compile.compiler(source, filename, symbol, ast.PyCF_ONLY_AST)
         except (OverflowError, SyntaxError, ValueError):
             self.showsyntaxerror(filename)
             return False
diff --git a/Lib/codeop.py b/Lib/codeop.py
index 6ad60e7f850..8a77075b487 100644
--- a/Lib/codeop.py
+++ b/Lib/codeop.py
@@ -44,6 +44,7 @@
 # Caveat emptor: These flags are undocumented on purpose and depending
 # on their effect outside the standard library is **unsupported**.
 PyCF_DONT_IMPLY_DEDENT = 0x200
+PyCF_ONLY_AST = 0x400
 PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
 
 def _maybe_compile(compiler, source, filename, symbol):
@@ -109,11 +110,13 @@ class Compile:
     def __init__(self):
         self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
 
-    def __call__(self, source, filename, symbol, **kwargs):
-        flags = self.flags
+    def __call__(self, source, filename, symbol, flags=0, **kwargs):
+        flags |= self.flags
         if kwargs.get('incomplete_input', True) is False:
             flags &= ~PyCF_DONT_IMPLY_DEDENT
             flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT
+        if flags & PyCF_ONLY_AST:
+            return compile(source, filename, symbol, flags, True)
         codeob = compile(source, filename, symbol, flags, True)
         for feature in _features:
             if codeob.co_flags & feature.compiler_flag:

@pablogsal
Copy link
Member

Clearly this is a showstopper bug requiring @Yhg1s to delay Python 3.13.0 for another week and another RC! No respect for the FLUFL eh @pablogsal ??? 😭

image

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

5 participants