Skip to content

Commit 67b8be8

Browse files
committed
Fix false E302 when there's a comment before the first function or class; issue #174
1 parent 6e4bffb commit 67b8be8

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Changelog
1717

1818
* Change misleading message for E251. (Issue #171)
1919

20+
* Do not report false E302 when the source file has a coding cookie or a
21+
comment on the first line. (Issue #174)
22+
2023

2124
1.4.4 (2013-02-24)
2225
------------------

pep8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
256256
E303: def a():\n\n\n\n pass
257257
E304: @decorator\n\ndef a():\n pass
258258
"""
259-
if line_number == 1:
259+
if line_number < 3 and not previous_logical:
260260
return # Don't expect blank lines before the first line
261261
if previous_logical.startswith('@'):
262262
if blank_lines:

testsuite/E30.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ def b():
1616
#:
1717

1818

19+
#: E302
20+
#!python
21+
# -*- coding: utf-8 -*-
22+
def a():
23+
pass
24+
#: E302
25+
"""Main module."""
26+
def _main():
27+
pass
28+
#: E302
29+
import sys
30+
def get_sys_path():
31+
return sys.path
1932
#: E302
2033
def a():
2134
pass

testsuite/E30not.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#: Okay
2+
class X:
3+
pass
4+
#: Okay
5+
6+
def foo():
7+
pass
8+
#: Okay
9+
# -*- coding: utf-8 -*-
10+
class X:
11+
pass
12+
#: Okay
13+
# -*- coding: utf-8 -*-
14+
def foo():
15+
pass
16+
#: Okay
117
class X:
218

319
def a():

0 commit comments

Comments
 (0)