Skip to content

Enable more linting #292

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ignore=tests

[MESSAGES CONTROL]
# messages up to fixme should probably be fixed somehow
disable = redefined-builtin,attribute-defined-outside-init,anomalous-backslash-in-string,no-self-use,redefined-outer-name,bad-continuation,wrong-import-order,superfluous-parens,no-member,duplicate-code,super-init-not-called,abstract-method,property-on-old-class,wrong-import-position,no-name-in-module,no-init,bad-mcs-classmethod-argument,bad-classmethod-argument,fixme,invalid-name,import-error,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-locals,too-many-lines,too-many-public-methods,too-many-return-statements,too-many-statements,missing-docstring,line-too-long,locally-disabled,locally-enabled,bad-builtin,deprecated-lambda
disable = redefined-builtin,attribute-defined-outside-init,anomalous-backslash-in-string,no-self-use,redefined-outer-name,bad-continuation,wrong-import-order,superfluous-parens,no-member,duplicate-code,super-init-not-called,abstract-method,property-on-old-class,wrong-import-position,no-name-in-module,no-init,bad-mcs-classmethod-argument,bad-classmethod-argument,fixme,invalid-name,import-error,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-locals,too-many-lines,too-many-public-methods,too-many-return-statements,too-many-statements,missing-docstring,line-too-long,locally-disabled,locally-enabled,bad-builtin,deprecated-lambda,bad-option-value,star-args,abstract-class-little-used,abstract-class-not-used

[FORMAT]
max-line-length=139
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ script:
- if [[ $TRAVIS_PYTHON_VERSION == pypy* ]]; then py.test; fi
- if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then coverage run -m pytest; fi
- bash flake8-run.sh
- pylint --rcfile=.pylintrc html5lib

after_script:
- python debug-info.py
Expand Down
2 changes: 1 addition & 1 deletion debug-info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function, unicode_literals
from __future__ import absolute_import, division, print_function, unicode_literals

import platform
import sys
Expand Down
1 change: 1 addition & 0 deletions flake8-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ if [[ ! -x $(which flake8) ]]; then
exit 1
fi

flake8 --version
flake8 `dirname $0`
exit $?
20 changes: 11 additions & 9 deletions html5lib/_inputstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ def position(self):
return (line + 1, col)

def char(self):
""" Read one character from the stream or queue if available. Return
EOF when EOF is reached.
"""Read one character from the stream or queue if available.

Return EOF when EOF is reached.
"""
# Read a new chunk from the input stream if necessary
if self.chunkOffset >= self.chunkSize:
Expand Down Expand Up @@ -318,7 +319,7 @@ def characterErrorsUCS2(self, data):
self.errors.append("invalid-codepoint")

def charsUntil(self, characters, opposite=False):
""" Returns a string of characters from the stream up to but not
"""Returns a string of characters from the stream up to but not
including any character in 'characters' or EOF. 'characters' must be
a container that supports the 'in' method and iteration over its
characters.
Expand All @@ -330,7 +331,7 @@ def charsUntil(self, characters, opposite=False):
except KeyError:
if __debug__:
for c in characters:
assert(ord(c) < 128)
assert ord(c) < 128
regex = "".join(["\\x%02x" % ord(c) for c in characters])
if not opposite:
regex = "^%s" % regex
Expand Down Expand Up @@ -449,7 +450,7 @@ def openStream(self, source):

try:
stream.seek(stream.tell())
except: # pylint:disable=bare-except
except Exception: # pylint: disable=broad-except
stream = BufferedStream(stream)

return stream
Expand Down Expand Up @@ -567,8 +568,7 @@ def detectBOM(self):
return None

def detectEncodingMeta(self):
"""Report the encoding declared by the meta element
"""
"""Report the encoding declared by the meta element."""
buffer = self.rawStream.read(self.numBytesMeta)
assert isinstance(buffer, bytes)
parser = EncodingParser(buffer)
Expand Down Expand Up @@ -686,10 +686,12 @@ def jumpTo(self, bytes):


class EncodingParser(object):
"""Mini parser for detecting character encoding from meta elements"""
"""Mini parser for detecting character encoding from meta elements."""

def __init__(self, data):
"""string - the data to work on for encoding detection"""
"""Constructor.

data - the data to work on for encoding detection"""
self.data = EncodingBytes(data)
self.encoding = None

Expand Down
10 changes: 4 additions & 6 deletions html5lib/_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class HTMLTokenizer(object):
""" This class takes care of tokenizing HTML.
"""This class takes care of tokenizing HTML.

* self.currentToken
Holds the token that is currently being processed.
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self, stream, parser=None, **kwargs):
super(HTMLTokenizer, self).__init__()

def __iter__(self):
""" This is where the magic happens.
"""This is where the magic happens.

We do our usually processing through the states and when we have a token
to return we yield the token which pauses processing until the next token
Expand Down Expand Up @@ -215,8 +215,7 @@ def consumeEntity(self, allowedChar=None, fromAttribute=False):
self.tokenQueue.append({"type": tokenTypes[tokenType], "data": output})

def processEntityInAttribute(self, allowedChar):
"""This method replaces the need for "entityInAttributeValueState".
"""
"""This method replaces the need for "entityInAttributeValueState"."""
self.consumeEntity(allowedChar=allowedChar, fromAttribute=True)

def emitCurrentToken(self):
Expand Down Expand Up @@ -1686,8 +1685,7 @@ def bogusDoctypeState(self):
self.stream.unget(data)
self.tokenQueue.append(self.currentToken)
self.state = self.dataState
else:
pass

return True

def cdataSectionState(self):
Expand Down
4 changes: 2 additions & 2 deletions html5lib/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
# We need this with u"" because of http://bugs.jython.org/issue2039
_x = eval('u"\\uD800"') # pylint:disable=eval-used
assert isinstance(_x, text_type)
except: # pylint:disable=bare-except
except Exception: # pylint: disable=broad-except
supports_lone_surrogates = False
else:
supports_lone_surrogates = True


class MethodDispatcher(dict):
"""Dict with 2 special properties:
"""Dict with 2 special properties.

On initiation, keys that are lists, sets or tuples are converted to
multiple keys so accessing any one of the items in the original
Expand Down
2 changes: 1 addition & 1 deletion html5lib/filters/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@


class Filter(base.Filter):
""" sanitization of XHTML+MathML+SVG and of inline style attributes."""
"""Sanitization of XHTML+MathML+SVG and of inline style attributes."""
def __init__(self,
source,
allowed_elements=allowed_elements,
Expand Down
25 changes: 10 additions & 15 deletions html5lib/html5parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def __new__(meta, classname, bases, classDict):

class HTMLParser(object):
"""HTML parser. Generates a tree structure from a stream of (possibly
malformed) HTML"""
malformed) HTML"""

def __init__(self, tree=None, strict=False, namespaceHTMLElements=True, debug=False):
"""
"""Constructor.

strict - raise an exception when a parse error is encountered

tree - a treebuilder class controlling the type of tree that will be
Expand Down Expand Up @@ -108,10 +109,9 @@ def reset(self):
self.tokenizer.state = self.tokenizer.rawtextState
elif self.innerHTML == 'plaintext':
self.tokenizer.state = self.tokenizer.plaintextState
else:
# state already is data state
# self.tokenizer.state = self.tokenizer.dataState
pass
# else state already is data state
# i.e. self.tokenizer.state = self.tokenizer.dataState

self.phase = self.phases["beforeHtml"]
self.phase.insertHtmlElement()
self.resetInsertionMode()
Expand Down Expand Up @@ -262,7 +262,7 @@ def parseError(self, errorcode="XXX-undefined-error", datavars=None):
raise ParseError(E[errorcode] % datavars)

def normalizeToken(self, token):
""" HTML5 specific normalizations to the token stream """
"""HTML5 specific normalizations to the token stream."""

if token["type"] == tokenTypes["StartTag"]:
raw = token["data"]
Expand Down Expand Up @@ -358,10 +358,7 @@ def log(function):
def wrapped(self, *args, **kwargs):
if function.__name__.startswith("process") and len(args) > 0:
token = args[0]
try:
info = {"type": type_names[token['type']]}
except:
raise
info = {"type": type_names[token['type']]}
if token['type'] in tagTokenTypes:
info["name"] = token['name']

Expand All @@ -383,8 +380,7 @@ def getMetaclass(use_metaclass, metaclass_func):

# pylint:disable=unused-argument
class Phase(with_metaclass(getMetaclass(debug, log))):
"""Base class for helper object that implements each phase of processing
"""
"""Base class for helper object that implements each phase of processing."""

def __init__(self, parser, tree):
self.parser = parser
Expand Down Expand Up @@ -1285,7 +1281,7 @@ def startTagSvg(self, token):
token["selfClosingAcknowledged"] = True

def startTagMisplaced(self, token):
""" Elements that should be children of other elements that have a
"""Elements that should be children of other elements that have a
different insertion mode; here they are ignored
"caption", "col", "colgroup", "frame", "frameset", "head",
"option", "optgroup", "tbody", "td", "tfoot", "th", "thead",
Expand Down Expand Up @@ -2730,4 +2726,3 @@ def impliedTagToken(name, type="EndTag", attributes=None,

class ParseError(Exception):
"""Error in parsed document"""
pass
5 changes: 2 additions & 3 deletions html5lib/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ def __init__(self, **kwargs):
self.strict = False

def encode(self, string):
assert(isinstance(string, text_type))
assert isinstance(string, text_type)
if self.encoding:
return string.encode(self.encoding, "htmlentityreplace")
else:
return string

def encodeStrict(self, string):
assert(isinstance(string, text_type))
assert isinstance(string, text_type)
if self.encoding:
return string.encode(self.encoding, "strict")
else:
Expand Down Expand Up @@ -331,4 +331,3 @@ def serializeError(self, data="XXX ERROR MESSAGE NEEDED"):

class SerializeError(Exception):
"""Error in serialized tree"""
pass
2 changes: 2 additions & 0 deletions html5lib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, unicode_literals

import os.path

import pkg_resources
Expand Down
8 changes: 5 additions & 3 deletions html5lib/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
}

try:
import lxml.etree as lxml # noqa
import lxml.etree as lxml
del lxml
except ImportError:
treeTypes['lxml'] = None
else:
Expand All @@ -60,7 +61,8 @@

# Genshi impls
try:
import genshi # noqa
import genshi
del genshi
except ImportError:
treeTypes["genshi"] = None
else:
Expand Down Expand Up @@ -132,7 +134,7 @@ def normaliseOutput(self, data):

def convert(stripChars):
def convertData(data):
"""convert the output of str(document) to the format used in the testcases"""
"""Convert the output of str(document) to the format used in the testcases"""
data = data.split("\n")
rv = []
for line in data:
Expand Down
5 changes: 3 additions & 2 deletions html5lib/tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import absolute_import, division, unicode_literals
from __future__ import absolute_import, division, print_function, unicode_literals

import os

Expand Down Expand Up @@ -105,7 +105,8 @@ def test_encoding():

# pylint:disable=wrong-import-position
try:
import chardet # noqa
import chardet
del chardet
except ImportError:
print("chardet not found, skipping chardet tests")
else:
Expand Down
6 changes: 5 additions & 1 deletion html5lib/tests/test_parser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

import io

from . import support # noqa
from . import support


from html5lib.constants import namespaces, tokenTypes
from html5lib import parse, parseFragment, HTMLParser

# above import has side-effects; mark it as used and del it
del support


# tests that aren't autogenerated from text files
def test_assertDoctypeCloneable():
Expand Down
4 changes: 2 additions & 2 deletions html5lib/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _convertAttrib(self, attribs):
attrs = {}
for attrib in attribs:
name = (attrib["namespace"], attrib["name"])
assert(name not in attrs)
assert name not in attrs
attrs[name] = attrib["value"]
return attrs

Expand All @@ -93,7 +93,7 @@ def runSerializerTest(input, expected, options):
encoding = options.get("encoding", None)

if encoding:
expected = list(map(lambda x: x.encode(encoding), expected))
expected = list(x.encode(encoding) for x in expected)

result = serialize_html(input, options)
if len(expected) == 1:
Expand Down
15 changes: 9 additions & 6 deletions html5lib/tests/test_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import, division, unicode_literals

from . import support # noqa

import codecs
import sys
from io import BytesIO, StringIO
Expand All @@ -11,10 +9,15 @@
import six
from six.moves import http_client, urllib

from . import support

from html5lib._inputstream import (BufferedStream, HTMLInputStream,
HTMLUnicodeInputStream, HTMLBinaryInputStream)
from html5lib._utils import supports_lone_surrogates

# above import has side-effects; mark it as used and del it
del support


def test_basic():
s = b"abc"
Expand Down Expand Up @@ -182,8 +185,8 @@ def test_position2():


def test_python_issue_20007():
"""
Make sure we have a work-around for Python bug #20007
"""Ensure we have a work-around for Python bug #20007.

http://bugs.python.org/issue20007
"""
class FakeSocket(object):
Expand All @@ -198,8 +201,8 @@ def makefile(self, _mode, _bufsize=None):


def test_python_issue_20007_b():
"""
Make sure we have a work-around for Python bug #20007
"""Ensure we have a work-around for Python bug #20007 (part b).

http://bugs.python.org/issue20007
"""
if six.PY2:
Expand Down
Loading