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

PR: Avoid comments to generate pep8 warnings #4651

Merged
merged 3 commits into from Jun 30, 2017

Conversation

Ericvulpi
Copy link
Contributor

@Ericvulpi Ericvulpi commented Jun 25, 2017

Fixes #1785.


Comment function : adds a space after the comment string (# for Python)
Uncomment function : removes the comment string and removes one space
if there is one

Comment function : adds a space after the comment string (# for Python)
Uncomment function : removes the comment string and removes one space
if there is one
@Ericvulpi
Copy link
Contributor Author

3rd time is the charm ... hopefully

@ccordoba12 ccordoba12 changed the title Fix to issue #1785 regarding comment function in the editor PR: Avoid comments to generate pep8 warnings Jun 26, 2017
@ccordoba12 ccordoba12 requested a review from dalthviz June 26, 2017 21:31
@ccordoba12 ccordoba12 added this to the v3.2 milestone Jun 26, 2017
@ccordoba12
Copy link
Member

@Ericvulpi, thanks a lot for your contribution.

@dalthviz, please review this one.


def uncomment(self):
"""Uncomment current line or selection."""
self.remove_prefix(self.comment_string)
self.remove_prefix(" ")

def __blockcomment_bar(self):
return self.comment_string + '='*(79-len(self.comment_string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ericvulpi I think that we need to change the line above like you proposed adding a space (' ') for the block comments. It should be something like:

        return self.comment_string + ' ' + '=' * (78 - len(self.comment_string))

You can test this with Ctrl+4 (blockcomment) and Ctrl+5 (unblockcomment). The change should make a block comment that starts with # ===... instead of #===... (note the space between the # and the = symbols).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was right under my nose! but i dont use block comments so didn't notice it

Added the block comment modification as suggested by dalthviz
@ccordoba12
Copy link
Member

@dalthviz, do you approve this one?

@dalthviz
Copy link
Member

@ccordoba12 I think the changes are ok, however I don't know the reason for the tests to fail.

@ccordoba12
Copy link
Member

@Ericvulpi, please rebase this one on top of our latest 3.x branch to fix the test errors. Then I'll merge :-)


def __blockcomment_bar(self):
return self.comment_string + '='*(79-len(self.comment_string))
return self.comment_string + ' ' + '=' * (78 - len(self.comment_string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that hardcoded 78?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is because of the space added between the comment string and the '='. Maybe this could be rewritten as:

return self.comment_string + ' ' + '=' * (79 - len(self.comment_string + ' '))

Copy link
Member

@goanpeca goanpeca Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I mean why is 79 hardcoded!!, that is an adjustable setting

screen shot 2017-06-28 at 12 52 03

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, then we should depend on that config here?, I think the 79 is from the maximum line length in PEP8

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalthviz is right, 79 is the default column width for pep8. This width can be configured for pycodestyle, but currently is not connected to our config system.

So let's leave 79 for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalthviz please open an issue to keep track of this missing connection

@ccordoba12
Copy link
Member

Thanks @Ericvulpi for your contribution, this is going in!

@ccordoba12 ccordoba12 merged commit 6141665 into spyder-ide:3.x Jun 30, 2017
ccordoba12 added a commit that referenced this pull request Jun 30, 2017
@Ericvulpi Ericvulpi deleted the Spyder--Fix-to-issue-#1785 branch July 3, 2017 20:00
@bcolsen
Copy link
Member

bcolsen commented Jul 6, 2017

@ccordoba12 This patch breaks backwards compatibility when uncommenting scripts with comments in code blocks. eg.

Script with old comment:

for i in range(10):
#    print(i) # Made with old comment system
    b = i + i

Now uncomment with latest 3.2:

for i in range(10):
   print(i) # Error
    b = i + i

Imagine a whole block of those with different block depths.(Maybe I this is a bad practice but I don't think I'm alone in this)

I can't even shift-tab and tab back to replace the 3 spaces with 4 (maybe another bug here)

I think pep8 errors are small compared to code errors introduced from uncommenting.

I would suggest holding off on this until we get comments like this:

for i in range(10):
    # print(i) # Made with old comment system
    b = i + i

This might break backward compatibility but at least I think this is waiting until 4.0.

@ccordoba12
Copy link
Member

ccordoba12 commented Jul 6, 2017

@bcolsen, thanks for your feedback. I think you're right, we need to revert this change.

@dalthviz, please create a PR to revert this.

@Ericvulpi, sorry for this, we'll fix this for good in Spyder 4.

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

Successfully merging this pull request may close these issues.

None yet

5 participants