You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
>>>
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.
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
If I now select the func and F9 it it will ignore the second print statement but insert an Enter consequently outputting:
What is the expected output? What do you see instead?
No indentation Error.
Here are some suggestions.
Either really ignoring the line like this:
or adding a special run case for indented blocks that would allow this through by displaying it but not running it maybe like this:
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:
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:
Versions and main components
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)
The text was updated successfully, but these errors were encountered: