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

E302 for multiline comment before class at beginning of file #108

Closed
asottile opened this issue Apr 3, 2021 · 4 comments
Closed

E302 for multiline comment before class at beginning of file #108

asottile opened this issue Apr 3, 2021 · 4 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @dradetsky on Jun 25, 2015, 12:58

Not certain that this is a flake8 bug rather than a bug in a flake8 component. In any case, see the stackoverflow discussion:

http://stackoverflow.com/questions/31058607/how-to-fix-flake8-pyflakes-treats-multiline-comment-before-class-as-error

I'm using flake8 with emacs. If I begin a file with

# comment comment comment comment comment comment comment comment comment comment
class Foo(object):
    pass

It says there is no syntax error. But if I wrap it to:

# comment comment comment comment comment comment comment comment
# comment comment
class Foo(object):
    pass

I get "E302 expected 2 blank lines, found 0" for the "class" line.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jun 26, 2015, 06:15

This is a bug in pep8. Please check for already opened bug reports before filing a new one.

~ ❯❯❯ cat foo.py; pep8 foo.py
# comment comment comment comment comment comment comment comment comment
# comment
class Foo(object):
    pass
foo.py:3:1: E302 expected 2 blank lines, found 0

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @dradetsky on Jun 26, 2015, 08:11

Sorry. Found issue PyCQA/pycodestyle#174

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jun 26, 2015, 11:16

No need to apologize! Thanks for finding this! You're improving the quality of pep8 and flake8. =D

@asottile asottile closed this as completed Apr 3, 2021
@tonybp18
Copy link

tonybp18 commented Feb 9, 2023

Just found that flake8 doesn't consider comments as blank lines,
In my case I had a single method and 2 TODO on top of my method

1. import requests
2. 
3. # TODO: 1
4. # TODO: 2
5. def fooBar(foo, bar):
6.    print("" + requests.get(''))

In my head, lines 2,3 and 4 are considered white spaces, but flake8 only counts line 2 (missiging a second line as stated in error E302)

The solution is to add a new line (the missing one) on line 2, with this rule will pass.

1. import requests
2. 
3. 
4. # TODO: 1
5. # TODO: 2
6. def fooBar(foo, bar):
7.    print("" + requests.get(''))

Not that obvious, but wanted to share the solution.

P.D.: They need to be consecutive, this example doesn't work for the count

1. import requests
2. 
3. # TODO: 1
4. 
5. # TODO: 2
6. def fooBar(foo, bar):
7.    print("" + requests.get(''))

Havin line 2 and 4 as "2 blank lines" before the method is not enoug to make the rule pass

Best,

@PyCQA PyCQA locked and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants