Skip to content

gh-118894: Make asyncio REPL use pyrepl#119433

Merged
ambv merged 9 commits into
python:mainfrom
ambv:asyncio-pyrepl
May 31, 2024
Merged

gh-118894: Make asyncio REPL use pyrepl#119433
ambv merged 9 commits into
python:mainfrom
ambv:asyncio-pyrepl

Conversation

@ambv

@ambv ambv commented May 22, 2024

Copy link
Copy Markdown
Contributor
  • support PYTHON_BASIC_REPL
  • make exit() and exit behave the same
  • show KeyboardInterrupt on CTRL-C like regular pyrepl
  • show convenience asyncio auto-import
  • make sure history saves

@ambv ambv added the topic-repl Related to the interactive shell label May 22, 2024

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @ambv. It's so great to see the PyREPL come to life.

P.S. Code looks good but Windows is grumpy.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for thinking of this! I’m AFK, but can review later. Wondering though… Could we change ‘code’ to always use this?

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I can review the changes to _pyrepl itself, but here's a review of the asyncio changes. Nothing earth-shattering. :-)

Comment thread Lib/asyncio/__main__.py
Comment thread Lib/asyncio/__main__.py
@gvanrossum

Copy link
Copy Markdown
Member

Another difference (inspired by the issue): If you hit ^C this just prints a blank line; the real REPL prints a message KeyboardInterrupt. That's not a new difference though.

@ambv

ambv commented May 24, 2024

Copy link
Copy Markdown
Contributor Author

Could we change ‘code’ to always use this?

Interesting idea. We'll consider it for Python 3.14.

@gvanrossum

Copy link
Copy Markdown
Member

The asyncio part LGTM now. Thanks again!

Comment thread Lib/_pyrepl/console.py
def repaint(self) -> None: ...


class InteractiveColoredConsole(code.InteractiveConsole):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this here so it can be imported even when _pyrepl.readline doesn't import (which is imported by _pyrepl.simple_interact).

Comment thread Lib/_pyrepl/console.py
the_symbol = symbol if stmt is last_stmt else "exec"
item = wrapper([stmt])
try:
code = self.compile.compiler(item, filename, the_symbol, dont_inherit=True)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually want to use our console's compiler because then we can set custom flags, like top-level await.

Comment thread Lib/_pyrepl/console.py
Comment on lines +179 to +182
e.add_note(
f"Try the asyncio REPL ({python} -m asyncio) to use"
f" top-level 'await' and run background asyncio tasks."
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python REPL, now with ads.

@ambv ambv merged commit 2237946 into python:main May 31, 2024
@ambv ambv added the needs backport to 3.13 bugs and security fixes label May 31, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @ambv for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@ambv ambv deleted the asyncio-pyrepl branch May 31, 2024 20:26
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 31, 2024
(cherry picked from commit 2237946)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@bedevere-app

bedevere-app Bot commented May 31, 2024

Copy link
Copy Markdown

GH-119884 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 31, 2024
ambv added a commit that referenced this pull request May 31, 2024
(cherry picked from commit 2237946)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@gvanrossum

Copy link
Copy Markdown
Member

Whoopee! I was going to propose to make this the default, but there are some issues, e.g. creating a thread and an event loop by default. Still, very happy with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-repl Related to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants