Skip to content

Support multiline function/class definitions in REPL and InteractiveConsole #5743

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 3 commits into from
Apr 30, 2025

Conversation

aneeshdurg
Copy link
Contributor

This makes it possible to define functions/classes interactively.

@aneeshdurg
Copy link
Contributor Author

Please let me know if there's a good place to add tests for this!

This is definitely a short-term fix though, and a better long term solution would be do what cPython does, and have a subclass of SyntaxException errors that indicate that it could be incomplete input. Also, it would probably be better to have the shell just execute code.InteractiveConsole().interact() instead of maintaining two implementations - I'd love to take a stab at that if that's something you'd like to see!

@arihant2math
Copy link
Collaborator

Hopefully once ctypes works _pyrepl will become the default, but this is a good fix.

@arihant2math arihant2math added the C-enhancement New feature or request label Apr 25, 2025
@arihant2math
Copy link
Collaborator

arihant2math commented Apr 25, 2025

Actually I would like to test this first locally atleast, since there are no tests by the looks of it.

@aneeshdurg
Copy link
Contributor Author

I'd be happy to add tests if there's already somewhere with tests of the REPL?
If there isn't, I'd also be interested in helping add those, but that seems like it should be a separate PR.

@arihant2math
Copy link
Collaborator

I expected the cpython test-suite to have repl tests, but it doesn't. We don't really need tests I suppose.
I apologize for the confusion.

@aneeshdurg
Copy link
Contributor Author

@arihant2math just to confirm is there anything you need from me to proceed with review? I've got some other patches I'm working on to make this work more generally, and to also enable PY_CF_ALLOW_INCOMPLETE_INPUT in the python parser/compiler

@arihant2math arihant2math requested a review from youknowone April 29, 2025 00:42
@arihant2math
Copy link
Collaborator

LGTM.
@youknowone please review/merge.

@youknowone
Copy link
Member

I am sorry. Just distracted a bit by recent CI trouble. The patch looks good

@youknowone
Copy link
Member

I've got some other patches I'm working on to make this work more generally, and to also enable PY_CF_ALLOW_INCOMPLETE_INPUT in the python parser/compiler

@aneeshdurg Instead of sending patch based on main branch, you can create new branch as many as you want. That helps to create multiple patches at same time.

@youknowone
Copy link
Member

I fixed comment of codeop.py a bit.

@youknowone youknowone merged commit e49e743 into RustPython:main Apr 30, 2025
@youknowone
Copy link
Member

Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants