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