diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..268fd3a8 --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +ignore = + # Refers to the max-line length. Let's suppress the error and simply + # let black take care on how it wants to format the lines. + E501, + + # Refers to "line break before/after binary operator". + # Similar to above, let black take care of the formatting. + W503, + W504, + + # black disagrees with flake8, and inserts whitespace + E203, # whitespace before ':' diff --git a/pytest.ini b/pytest.ini index 68cfd625..515b2196 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,19 +1,2 @@ [pytest] doctest_optionflags = ALLOW_UNICODE ALLOW_BYTES -flake8-max-line-length = 88 -flake8-ignore = - W503 # https://www.flake8rules.com/rules/W503.html - E203 # https://www.flake8rules.com/rules/E203.html - - docs/conf.py E121 E122 E265 E401 - tests/test_encoding.py E128 E221 E241 E302 E401 E501 E731 - tests/test_form.py E265 - tests/test_html.py E123 E128 E241 E303 E501 E502 - tests/test_http.py E128 E261 E302 W291 - tests/test_url.py E126 E127 E128 E226 E261 E303 E501 W293 W391 - w3lib/encoding.py E126 E128 E302 E305 E401 E501 - w3lib/form.py E402 E501 E721 - w3lib/html.py E128 E302 E501 E502 W504 - w3lib/http.py E501 - w3lib/url.py E128 E261 E302 E305 E501 F841 W291 W293 W504 - w3lib/util.py E302 diff --git a/tests/test_encoding.py b/tests/test_encoding.py index dfda2032..865cf720 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -280,7 +280,9 @@ def test_html_encoding(self): self._assert_encoding_detected(None, "utf-8", codecs.BOM_UTF8 + body) def test_autodetect(self): - asciif = lambda x: "ascii" + def asciif(x): + return "ascii" + body = b"""""" # body encoding takes precedence self._assert_encoding_detected(None, "utf-8", body, auto_detect_fun=asciif) diff --git a/tox.ini b/tox.ini index aae72b69..5647f5a1 100644 --- a/tox.ini +++ b/tox.ini @@ -27,17 +27,17 @@ basepython = python3 deps = # mypy would error if pytest (or its sub) not found pytest - mypy==0.910 + mypy==0.971 commands = mypy --show-error-codes {posargs: w3lib tests} [testenv:flake8] basepython = python3 deps = - {[testenv]deps} - pytest-flake8 + flake8 commands = - pytest --flake8 + flake8 \ + {posargs:w3lib tests setup.py} [testenv:pylint] deps = @@ -48,7 +48,7 @@ commands = [testenv:black] deps = - black==22.3.0 + black==22.6.0 commands = black --check {posargs:conftest.py setup.py tests w3lib} diff --git a/w3lib/encoding.py b/w3lib/encoding.py index 86b678be..db5a2b25 100644 --- a/w3lib/encoding.py +++ b/w3lib/encoding.py @@ -1,8 +1,11 @@ """ Functions for handling encoding of web pages """ -import re, codecs, encodings +import re +import codecs +import encodings from typing import Callable, Match, Optional, Tuple, Union, cast + from w3lib._types import AnyUnicodeError, StrOrBytes import w3lib.util