Spyder: F9 does not know to expect more code after function definition

Created on 1 Feb 2017  路  8Comments  路  Source: spyder-ide/spyder

If we press F9 on the line of function definition, it produces SyntaxError: unexpected EOF while parsing. I expect Spyder to recognize that it's on a line defining a function. It should expect more code to follow and terminate only after the function's body (i.e. no more indentation).

What steps will reproduce the problem?

  1. Write code below
def square(x):
    return(x ** 2)
  1. Press F9 on the first line
  2. Error SyntaxError: unexpected EOF while parsing

Versions and main components

  • Spyder Version: 3.1.2
  • Python Version: Python 3.5.2
  • Operating system: Ubuntu 16.04

Dependencies

jedi >=0.8.1 : 0.9.0 (OK)
matplotlib >=1.0 : 2.0.0 (OK)
nbconvert >=4.0 : 4.2.0 (OK)
numpy >=1.7 : 1.11.3 (OK)
pandas >=0.13.1 : 0.19.2 (OK)
pep8 >=0.6 : 1.7.0 (OK)
psutil >=0.3 : 5.0.1 (OK)
pyflakes >=0.6.0 : 1.5.0 (OK)
pygments >=2.0 : 2.1.3 (OK)
pylint >=0.25 : 1.6.4 (OK)
qtconsole >=4.2.0: 4.2.1 (OK)
rope >=0.9.4 : 0.9.4-1 (OK)
sphinx >=0.6.6 : 1.5.1 (OK)
sympy >=0.7.3 : 1.0 (OK)

Wontfix

Most helpful comment

I appreciate that this might not be simple to implement but I would also like to add my opinion that this would be a very valuable addition for the reasons @LaDilettante mentioned - when doing data analysis in R this ability exists to write a script but step through it as you code (with Ctrl+Enter) and when doing this on a line that starts a function, it will execute the entire function. This is a very valuable and time-saving piece of functionality.

All 8 comments

F9 tries to evaluate the current line if there is no selection available. That's how it's defined.

If you're trying to evaluate the first line of a function definition, it'll obviously generate an error.

If you want to evaluate more complex expressions, you need to use cells.

I understand that F9 is doing what it should -- this is a feature request instead of a bug report.

I think the ideal goal is for the analyst to be able to "F9"-ing through their code from start to finish without stopping to highlight or use cell. Whether this is worthwhile is up to the developers.

"F9"-ing means exactly what I said: evaluating a line. If the evaluation of a line generates errors, it's the user who has to fix them, not Spyder to guess when to run an evaluation and when not to do it.

So if you can't run a file line by line with F9, then you have to reorganize your code to make it possible, e.g. by moving function/class definitions to another file, and then importing those in your analysis file.

Sorry but we don't have time to try to implement this request, something that it's not easy at all.

@LaDilettante It seems to me that you want to run your code in debug mode. I believe it does exactly what you want, evaluates one line at the time. You can enter debug mode by pressing Ctrl+F5 and then use the buttons at the top to navigate or the provided shortcuts. here's the docs on the python debugger (pdb)

@nbonacchi thanks for the comment but I want to do it in regular mode for interactive data analysis. The idea comes from RStudio, where you can step through the code line by line and if it sees a function definition it knows to wait for the entirety of the function definition.

I suppose this is just a small quality of life feature of RStudio and not universally expected.

I appreciate that this might not be simple to implement but I would also like to add my opinion that this would be a very valuable addition for the reasons @LaDilettante mentioned - when doing data analysis in R this ability exists to write a script but step through it as you code (with Ctrl+Enter) and when doing this on a line that starts a function, it will execute the entire function. This is a very valuable and time-saving piece of functionality.

You must select all what you need and later press f9.

just started using spyder after having been using rstudio for the past 2 years, and I agree very much with @anhqle and @Geof11061. This feature would add value to spyder.

Was this page helpful?
0 / 5 - 0 ratings