Skip to content

Commit 00aff36

Browse files
committed
Fix BOM for Python 3 too, add changelog entry
1 parent e65d581 commit 00aff36

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Changelog
2020
* Do not crash when running AST checks and the document contains null bytes.
2121
(Issue #184)
2222

23+
* Fix false positive E261/E262 when the file contains a BOM. (Issue #193)
24+
2325

2426
1.4.5 (2013-03-06)
2527
------------------

pep8.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ def readlines(filename):
10171017
finally:
10181018
f.close()
10191019

1020+
BOM_UTF8 = '\xef\xbb\xbf'
10201021
isidentifier = re.compile(r'[a-zA-Z_]\w*').match
10211022
stdin_get_value = sys.stdin.read
10221023
else:
@@ -1035,6 +1036,7 @@ def readlines(filename):
10351036
finally:
10361037
f.close()
10371038

1039+
BOM_UTF8 = '\ufeff'
10381040
isidentifier = str.isidentifier
10391041

10401042
def stdin_get_value():
@@ -1200,9 +1202,8 @@ def __init__(self, filename=None, lines=None,
12001202
self.lines = []
12011203
else:
12021204
self.lines = lines
1203-
bom = '\xEF\xBB\xBF'
1204-
if len(self.lines) and self.lines[0].startswith(bom):
1205-
self.lines[0] = self.lines[0][len(bom):]
1205+
if self.lines and self.lines[0].startswith(BOM_UTF8):
1206+
self.lines[0] = self.lines[0][len(BOM_UTF8):]
12061207
self.report = report or options.report
12071208
self.report_error = self.report.error
12081209

0 commit comments

Comments
 (0)