Skip to content

Commit d12331e

Browse files
committed
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.
1 parent a8b40b2 commit d12331e

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ matrix:
1414
exclude:
1515
- python: "2.7"
1616
env: USE_OPTIONAL=false
17+
- python: "3.3"
18+
env: USE_OPTIONAL=false
1719
include:
1820
- python: "2.7"
1921
env: USE_OPTIONAL=false FLAKE=true
22+
- python: "3.3"
23+
env: USE_OPTIONAL=false FLAKE=true
2024

2125
before_install:
2226
- git submodule update --init --recursive

html5lib/tests/tokenizertotree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def main(out_path):
2525

2626
def run_file(filename, out_path):
2727
try:
28-
tests_data = json.load(file(filename))
28+
tests_data = json.load(open(filename, "r"))
2929
except ValueError:
3030
sys.stderr.write("Failed to load %s\n" % filename)
3131
return

html5lib/tokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import, division, unicode_literals
22

33
try:
4-
chr = unichr
4+
chr = unichr # flake8: noqa
55
except NameError:
66
pass
77

html5lib/treebuilders/etree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def tostring(element):
259259
filter = ihatexml.InfosetFilter()
260260

261261
def serializeElement(element):
262-
if type(element) == type(ElementTree.ElementTree):
262+
if isinstance(element, ElementTree.ElementTree):
263263
element = element.getroot()
264264

265265
if element.tag == "<!DOCTYPE>":

html5lib/treebuilders/etree_lxml.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
fullTree = True
3030
tag_regexp = re.compile("{([^}]*)}(.*)")
3131

32+
comment_type = etree.Comment("asd").tag
33+
3234

3335
class DocumentType(object):
3436
def __init__(self, name, publicId, systemId):
@@ -86,7 +88,7 @@ def serializeElement(element, indent=0):
8688
rv.append("#document-fragment")
8789
for next_element in element:
8890
serializeElement(next_element, indent + 2)
89-
elif type(element.tag) == type(etree.Comment):
91+
elif element.tag == comment_type:
9092
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
9193
if hasattr(element, "tail") and element.tail:
9294
rv.append("|%s\"%s\"" % (' ' * indent, element.tail))
@@ -149,7 +151,7 @@ def serializeElement(element):
149151
rv.append(dtd_str)
150152
serializeElement(element.getroot())
151153

152-
elif type(element.tag) == type(etree.Comment):
154+
elif element.tag == comment_type:
153155
rv.append("<!--%s-->" % (element.text,))
154156

155157
else:
@@ -301,7 +303,7 @@ def insertCommentInitial(self, data, parent=None):
301303

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy