-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-124960: Fixed barry_as_FLUFL
future flag does not work in new REPL
#124999
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
Changes from 8 commits
77cb340
9127c6c
d0049a3
904c202
cc807ee
cf96285
2080b24
5dde260
4bc4bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,13 +119,38 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self): | |
|
||
def test_no_active_future(self): | ||
console = InteractiveColoredConsole() | ||
source = "x: int = 1; print(__annotate__(1))" | ||
source = dedent("""\ | ||
x: int = 1 | ||
print(__annotate__(1)) | ||
""") | ||
f = io.StringIO() | ||
with contextlib.redirect_stdout(f): | ||
result = console.runsource(source) | ||
self.assertFalse(result) | ||
self.assertEqual(f.getvalue(), "{'x': <class 'int'>}\n") | ||
|
||
def test_future_annotations(self): | ||
console = InteractiveColoredConsole() | ||
source = dedent("""\ | ||
from __future__ import annotations | ||
def g(x: int): ... | ||
print(g.__annotations__) | ||
""") | ||
f = io.StringIO() | ||
with contextlib.redirect_stdout(f): | ||
result = console.runsource(source) | ||
self.assertFalse(result) | ||
self.assertEqual(f.getvalue(), "{'x': 'int'}\n") | ||
|
||
def test_future_barry_as_flufl(self): | ||
console = InteractiveColoredConsole() | ||
f = io.StringIO() | ||
with contextlib.redirect_stdout(f): | ||
result = console.runsource("from __future__ import barry_as_FLUFL\n") | ||
result = console.runsource("""print("black" <> 'blue')\n""") | ||
Comment on lines
+148
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required because the parser can't deal with the future import changing the flags inside a run. This is true now: ❯ ./python.exe -c "from __future__ import barry_as_FLUFL; 1<>0"
File "<string>", line 1
from __future__ import barry_as_FLUFL; 1<>0
^^
SyntaxError: invalid syntax but was also true in the old parser: ❯ python3.9 -Xoldparser -c "from __future__ import barry_as_FLUFL; 1<>0"
File "<string>", line 1
from __future__ import barry_as_FLUFL; 1<>0
^
SyntaxError: invalid syntax The consequence of that with PyREPL is that you cannot paste multiline blocks with that future and make them run, because PyREPL executes everything save for the last line in one go. PyREPL isn't doing anything wrong here, it's just exposing the bug that was always there. Therefore, I'm not sure we should be working around this pasting thing for this one future. Other futures work fine, as you can see in the test added above. |
||
self.assertFalse(result) | ||
self.assertEqual(f.getvalue(), "True\n") | ||
|
||
|
||
class TestMoreLines(unittest.TestCase): | ||
def test_invalid_syntax_single_line(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix support for the ``barry_as_FLUFL`` future flag in the new REPL. |
Uh oh!
There was an error while loading. Please reload this page.