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

gh-118894: Make asyncio REPL use pyrepl #119433

Merged
merged 9 commits into from
May 31, 2024
Merged

gh-118894: Make asyncio REPL use pyrepl #119433

merged 9 commits into from
May 31, 2024

Conversation

ambv
Copy link
Contributor

@ambv ambv commented May 22, 2024

  • 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
Copy link
Contributor

@willingc willingc left a comment

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.

Copy link
Member

@gvanrossum gvanrossum left a comment

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?

Copy link
Member

@gvanrossum gvanrossum left a comment

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. :-)

Lib/asyncio/__main__.py Show resolved Hide resolved
Lib/asyncio/__main__.py Show resolved Hide resolved
@gvanrossum
Copy link
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
Copy link
Contributor Author

ambv commented May 24, 2024

Could we change ‘code’ to always use this?

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

@gvanrossum
Copy link
Member

The asyncio part LGTM now. Thanks again!

@@ -136,3 +139,45 @@ def wait(self) -> None:

@abstractmethod
def repaint(self) -> None: ...


class InteractiveColoredConsole(code.InteractiveConsole):
Copy link
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).

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
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 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
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
41 checks passed
@ambv ambv added the needs backport to 3.13 bugs and security fixes label May 31, 2024
@miss-islington-app
Copy link

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
Copy link

bedevere-app bot commented May 31, 2024

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
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.

None yet

3 participants