Skip to content

Get Flake8 looking clean #20

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

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Fix more flake8 issues.
It turns out flake8's behaviour differs between Python 2 and Python 3
because of the changes between the two, so run it on both on Travis.
  • Loading branch information
gsnedders committed Apr 13, 2013
commit 5b3cb3589be952b1919e2c59ee860ffa60e97e5b
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ env:

matrix:
exclude:
- python: "2.7"
env: USE_OPTIONAL=false
- python: "3.3"
env: USE_OPTIONAL=false
include:
- python: "2.7"
env: USE_OPTIONAL=false FLAKE=true
- python: "3.3"
env: USE_OPTIONAL=false FLAKE=true

Expand Down
2 changes: 1 addition & 1 deletion html5lib/tests/tokenizertotree.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(out_path):

def run_file(filename, out_path):
try:
tests_data = json.load(file(filename))
tests_data = json.load(open(filename, "r"))
except ValueError:
sys.stderr.write("Failed to load %s\n" % filename)
return
Expand Down
2 changes: 1 addition & 1 deletion html5lib/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, division, unicode_literals

try:
chr = unichr
chr = unichr # flake8: noqa
except NameError:
pass

Expand Down
2 changes: 1 addition & 1 deletion html5lib/treebuilders/etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def tostring(element):
filter = ihatexml.InfosetFilter()

def serializeElement(element):
if type(element) == type(ElementTree.ElementTree):
if isinstance(element, ElementTree.ElementTree):
element = element.getroot()

if element.tag == "<!DOCTYPE>":
Expand Down
6 changes: 3 additions & 3 deletions html5lib/treebuilders/etree_lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def serializeElement(element, indent=0):
rv.append("#document-fragment")
for next_element in element:
serializeElement(next_element, indent + 2)
elif type(element.tag) == type(etree.Comment):
elif isinstance(element.tag, etree.Comment):
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
if hasattr(element, "tail") and element.tail:
rv.append("|%s\"%s\"" % (' ' * indent, element.tail))
Expand Down Expand Up @@ -149,7 +149,7 @@ def serializeElement(element):
rv.append(dtd_str)
serializeElement(element.getroot())

elif type(element.tag) == type(etree.Comment):
elif isinstance(element.tag, etree.Comment):
rv.append("<!--%s-->" % (element.text,))

else:
Expand Down Expand Up @@ -301,7 +301,7 @@ def insertCommentInitial(self, data, parent=None):

def insertCommentMain(self, data, parent=None):
if (parent == self.document and
type(self.document._elementTree.getroot()[-1].tag) == type(etree.Comment)):
isinstance(self.document._elementTree.getroot()[-1].tag, etree.Comment)):
warnings.warn("lxml cannot represent adjacent comments beyond the root elements", DataLossWarning)
super(TreeBuilder, self).insertComment(data, parent)

Expand Down