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

Commenting one line in indented block breaks F9 run code in console #4075

Closed
nbonacchi opened this issue Jan 30, 2017 · 3 comments
Closed

Commenting one line in indented block breaks F9 run code in console #4075

nbonacchi opened this issue Jan 30, 2017 · 3 comments

Comments

@nbonacchi
Copy link

Description of your problem

If block commenting inside an indented block (func, class, etc.) not only the comment is inserted at pos 0 with no space (see bug #4073 ), but if one selects the indented code and F9's it the python console will yield an error for unexpected indent.

What steps will reproduce the problem?
Example: here's a func that has a line commented using Ctrl+1

def comment_indented_block():
    print('doing something')
#    print('doing something else that I will comment out')
    print('yet something else')

If I now select the func and F9 it it will ignore the second print statement but insert an Enter consequently outputting:

>>> def comment_indented_block():
...     print('doing something')
...                              # <-- this is the ignored line that still inserts a '\n'
>>>     print('yet something else')
  File "\<stdin>", line 1
    print('yet something else')
    ^
IndentationError: unexpected indent

What is the expected output? What do you see instead?
No indentation Error.
Here are some suggestions.

Either really ignoring the line like this:

>>> def comment_indented_block():
...     print('doing something')
...     print('yet something else')
>>>    

or adding a special run case for indented blocks that would allow this through by displaying it but not running it maybe like this:

>>> def comment_indented_block():
...     print('doing something')
#    print('doing something else that I will comment out')
...     print('yet something else')
>>>    

or even change the Ctrl+1 behavior to be context aware so inserting the comment char using a Ctrl+1 would insert expected number of spaces before '#' (and one space after!) like this:

>>> def comment_indented_block():
...     print('doing something')
...     # print('doing something else that I will comment out')
...     print('yet something else')
>>>    

Please provide any additional information below

I think that solution 3, changing the behavior of the block comment command to be context aware is probably not pep8 compatible as block comments would be harder to see at a glance.
The perfect fix would be solution 2, if one actually types out the func definition in the console the behavior is exactly as expected line that starts with '#' is displayed but ignored and next indented line is considered part of func like this:

>>> def something():
...     print('something')
... # nothing to see here
...     print('something_else')
... 
>>> something()
something
something_else
>>> 

Versions and main components

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

Dependencies

jedi >=0.8.1 : 0.9.0 (OK)
matplotlib >=1.0 : 1.5.3 (OK)
nbconvert >=4.0 : 4.2.0 (OK)
numpy >=1.7 : 1.11.1 (OK)
pandas >=0.13.1 : 0.18.1 (OK)
pep8 >=0.6 : 1.7.0 (OK)
psutil >=0.3 : 5.0.0 (OK)
pyflakes >=0.6.0 : 1.3.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.4.6 (OK)
sympy >=0.7.3 : 1.0 (OK)

@ccordoba12
Copy link
Member

This is going to be solved by PR #3958.

@ccordoba12 ccordoba12 added this to the v3.2 milestone Jan 31, 2017
@nbonacchi
Copy link
Author

Regarding PR #3958 I guess its a solution, but not sure it's the best option...
In any case thanks for pointing it out I would have referenced it if I had found it.

@ccordoba12 ccordoba12 modified the milestones: v3.2, v3.3 Feb 14, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.2, v3.2.1 Jun 13, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.2.1, v3.2.2, v3.2.3 Jul 26, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.x, Not sorted Oct 11, 2018
@goanpeca
Copy link
Member

I cannot reproduce this. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants