-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PR: Make running a single line work on partial statements (IPython console) #21557
base: master
Are you sure you want to change the base?
Conversation
Hello @ccordoba12! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2023-11-26 23:07:16 UTC |
Nice work! In the second example, I would have expected Spyder to execute lines 2+3; why is it waiting for line 4? |
Thanks @jitseniesen!
Because the So, the way I implemented this feature is that we execute code when we find an empty line or when a line is at a lesser indentation level than the initial one (which means we are at a different code block). A couple of other gifs to clarify that: |
I understand it now. It's not what I expected. I'd have thought that if the user press F9 on a line that is not a complete statement, Spyder would execute the statement that contains the line. Instead, in this PR the user should keep pressing F9 until a DEDENT or an empty line is encountered. To be honest, I am afraid that this might be just as confusing as the existing behaviour, but I'm curious what others think. |
That's what was suggested on issue #4431, but it's not easy to implement because it'd require to determine the scope of the line to do it. And what should we do in the case of nested
What I noticed is that users are baffled when trying to run a single, incomplete but valid line and get a |
So gave a check to the original issue and seems like the idea is for the Run line functionality to run full statements, right? Thinking about the approach here, seems like there are still cases where the Run line functionality could end up triggering a syntax error. Like, taking as an example a code snippet from the added tests, if we have something like: for i in range(2): # 1
print('foo') # 2
for j in range(2): # 3
if j > 0: # 4
print(j) # 5
else: # 6
print('bar') # 7
print('baz') # 8 If you start to use the Run line functionality from line 6 (the Overall seems like the approach here could be in a way an improvement to the run line functionality, but still has some behaviors which could be not so intuitive (like having to press multiples times) and seems to me that it does not completly cover the original issue (although I havent checked myself how RStudio handles this to be honest) 🤔 Maybe could be worthy to discuss this on a dev meeting? |
Description of Changes
This was a very confusing and continuous source of frustration for newbies, so I decided to fix it for Spyder 6.
A couple of gifs to show how it works:
Issue(s) Resolved
Fixes #4431.
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: