Skip to content

Commit 68c13e7

Browse files
committed
Allow disable of W601
While has_key no longer exists for python 3, there are still libraries which have this method and do not allow for 'key in dict'. This enables the "nopep8/noqa" methods of disabling the warning per-line. Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
1 parent 8d65869 commit 68c13e7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

pep8.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,16 @@ def comparison_type(logical_line):
951951
yield match.start(), "E721 do not compare types, use 'isinstance()'"
952952

953953

954-
def python_3000_has_key(logical_line):
954+
def python_3000_has_key(logical_line, noqa):
955955
r"""
956956
The {}.has_key() method is removed in the Python 3.
957957
Use the 'in' operation instead.
958958
959959
Okay: if "alph" in d:\n print d["alph"]
960960
W601: assert d.has_key('alph')
961961
"""
962+
if noqa:
963+
return
962964
pos = logical_line.find('.has_key(')
963965
if pos > -1:
964966
yield pos, "W601 .has_key() is deprecated, use 'in'"

0 commit comments

Comments
 (0)