-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-130698: Add safe methods to get prompts for new REPL #131110
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
base: main
Are you sure you want to change the base?
gh-130698: Add safe methods to get prompts for new REPL #131110
Conversation
- and for `unrecoverable` exceptions
Misc/NEWS.d/next/Library/2025-03-13-00-39-54.gh-issue-130698.o2aU3e.rst
Outdated
Show resolved
Hide resolved
…2aU3e.rst Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
# Conflicts: # Lib/_pyrepl/reader.py
…gey-miryanov/cpython into pythongh-130698-pyrepl-ps1-exception
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
…gey-miryanov/cpython into pythongh-130698-pyrepl-ps1-exception
|
I updated this PR because it had merge conflicts. Not sure what to do next though. |
|
@chris-eibl @tomasr8 Could you please take a look? Is there anything else I can do to move this PR forward? |
|
Had another look and agree that this is correct:
As pointed out in #131110 (comment), this stems from the fact that cPython only uses a primary and secondary prompt:
and we have to map that to I still think that your new E.g. cpython/Lib/_pyrepl/simple_interact.py Lines 134 to 135 in 246ed23
can become and all the other places @tomasr8 and I have mentioned above? Since that mapping seems to be confusing, only using Because AFAIR PyPy sometimes downstreams our changes, most probably ditching |
I have no preference here. Maybe a warning would be nice, that can easily be added if others want it. Your PR definitely fixes the issue, so LGTM 🚀 |
|
@chris-eibl Thanks a lot for such detailed answer! Working on this ... |
|
I left only I'm not sure should we use Also, I think we should leave as-is C modules, where |
|
@chris-eibl Could you please take a look? |
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Ups, quite a splash radius. Let's see how others like it.
Yes, it is, but chances are high this is rejected or shall go into its own PR? Still unsure about @tomasr8's comment
Most probably it is better to leave them alone. The way cPython uses it, they are always overwritten in If we'd like to strive for a least minimal change, then all defaults can be removed again and just return an empty string (like the old REPL did): def __get_prompt_str(prompt: object) -> str:
try:
return str(prompt)
except (MemoryError, SystemError):
raise
except Exception:
return ""That way the user at least get's a hint that something is flaky by neither seeing their expected prompt nor the default one, since atm no warnings are printed here. And we don't reinvent the wheel, there is already precedence ... See also #130698 (comment) of @skirpichev in the issue. Sorry for the back and forth, but simpler might be better? Up to you, just stopping here and waiting for the REPL maintainers to chime in is also an option ... |
Yes, I left it as it was because we always rewrite all prompts in
Yes, I think returning to the old behavior is a good idea now. At least it's simple and minimal. I'll wait a while for the pyrepl maintainer's opinion. If I don't hear back from anyone, I'll implement the old behavior. Thanks! |
It fixes cases when ps1, ps2, ps3, ps4 raise exception from
__str__.This PR still misses tests for Reader.arg, but maybe you can review the whole solution - do I drive in the right direction?Fixed for Reader.arg.