8000 gh-124960: Fixed `barry_as_FLUFL` future flag does not work in new REPL by Wulian233 · Pull Request #124999 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 9 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/_pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import __future__

from __future__ import annotations

Expand Down Expand Up @@ -160,6 +161,17 @@ def __init__(
) -> None:
super().__init__(locals=locals, filename=filename, local_exit=local_exit) # type: ignore[call-arg]
self.can_colorize = _colorize.can_colorize()
self.barry_as_FLUFL = False

def check_barry_as_FLUFL(self, tree):
if self.barry_as_FLUFL:
return
for node in ast.walk(tree):
if isinstance(node, ast.ImportFrom) and node.module == "__future__":
if any(alias.name == "barry_as_FLUFL" for alias in node.names):
self.compile.compiler.flags |= getattr(__future__, "barry_as_FLUFL").compiler_flag
self.barry_as_FLUFL = True
break

def showsyntaxerror(self, filename=None, **kwargs):
super().showsyntaxerror(filename=filename, **kwargs)
Expand All @@ -175,6 +187,7 @@ def _excepthook(self, typ, value, tb):
def runsource(self, source, filename="<input>", symbol="single"):
try:
tree = ast.parse(source)
self.check_barry_as_FLUFL(tree)
except (SyntaxError, OverflowError, ValueError):
self.showsyntaxerror(filename, source=source)
return False
Expand Down
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.
Loading
0