From 80ed02f27f3441b7e063261207e00256bfcb62c0 Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Fri, 7 Jun 2024 12:08:01 +0200 Subject: [PATCH] Fix typecheck after making it mandatory in CI and make sure (#77) * Fix typecheck after making it mandatory in CI and make sure * Reformat code after black upgrade * Linting fixes after pylint upgrade --- .cookiecutter/includes/mypy/disables | 3 +++ .cookiecutter/includes/pylint/disables | 3 +++ .cookiecutter/includes/tests/pylint/disables | 3 +++ pyproject.toml | 7 +++++++ src/h_matchers/interface.py | 1 + src/h_matchers/matcher/anything.py | 1 + src/h_matchers/matcher/collection/__init__.py | 1 + src/h_matchers/matcher/collection/_mixin/contains.py | 1 + src/h_matchers/matcher/combination.py | 1 + src/h_matchers/matcher/object.py | 1 + src/h_matchers/matcher/web/request.py | 1 + src/h_matchers/matcher/web/url/core.py | 1 + src/h_matchers/matcher/web/url/fluent.py | 1 + tests/pyproject.toml | 4 ++++ tests/unit/data_types.py | 1 + .../unit/h_matchers/matcher/collection/_mixin/size_test.py | 1 + .../unit/h_matchers/matcher/collection/_mixin/type_test.py | 1 + 17 files changed, 32 insertions(+) create mode 100644 .cookiecutter/includes/mypy/disables create mode 100644 .cookiecutter/includes/pylint/disables create mode 100644 .cookiecutter/includes/tests/pylint/disables diff --git a/.cookiecutter/includes/mypy/disables b/.cookiecutter/includes/mypy/disables new file mode 100644 index 0000000..e56df5f --- /dev/null +++ b/.cookiecutter/includes/mypy/disables @@ -0,0 +1,3 @@ +"no-redef", +"assignment", +"import-not-found", diff --git a/.cookiecutter/includes/pylint/disables b/.cookiecutter/includes/pylint/disables new file mode 100644 index 0000000..81fe79e --- /dev/null +++ b/.cookiecutter/includes/pylint/disables @@ -0,0 +1,3 @@ +# Lots of false positives +"no-value-for-parameter", + diff --git a/.cookiecutter/includes/tests/pylint/disables b/.cookiecutter/includes/tests/pylint/disables new file mode 100644 index 0000000..81fe79e --- /dev/null +++ b/.cookiecutter/includes/tests/pylint/disables @@ -0,0 +1,3 @@ +# Lots of false positives +"no-value-for-parameter", + diff --git a/pyproject.toml b/pyproject.toml index 1edfd68..53160e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -128,6 +128,10 @@ disable = [ # Issues to disable this for false positives, disabling it globally in the meantime https://github.com/PyCQA/pylint/issues/214 "duplicate-code", + + # Lots of false positives + "no-value-for-parameter", + ] good-names = [ @@ -147,6 +151,9 @@ warn_unused_ignores = true disable_error_code = [ # https://mypy.readthedocs.io/en/stable/error_code_list.html#code-import-untyped "import-untyped", + "no-redef", + "assignment", + "import-not-found", ] [[tool.mypy.overrides]] diff --git a/src/h_matchers/interface.py b/src/h_matchers/interface.py index b16d733..ca4fe5d 100644 --- a/src/h_matchers/interface.py +++ b/src/h_matchers/interface.py @@ -1,4 +1,5 @@ """The public interface class for comparing with things.""" + from h_matchers.matcher import collection from h_matchers.matcher import number as _number from h_matchers.matcher.anything import AnyThing diff --git a/src/h_matchers/matcher/anything.py b/src/h_matchers/matcher/anything.py index dfd916f..e0a6f90 100644 --- a/src/h_matchers/matcher/anything.py +++ b/src/h_matchers/matcher/anything.py @@ -1,4 +1,5 @@ """A matcher that matches anything.""" + from h_matchers.matcher.core import Matcher diff --git a/src/h_matchers/matcher/collection/__init__.py b/src/h_matchers/matcher/collection/__init__.py index 16d6d89..ec90cb6 100644 --- a/src/h_matchers/matcher/collection/__init__.py +++ b/src/h_matchers/matcher/collection/__init__.py @@ -1,4 +1,5 @@ """Flexible matchers for various collection types in a fluent style.""" + from types import GeneratorType from h_matchers.exception import NoMatch diff --git a/src/h_matchers/matcher/collection/_mixin/contains.py b/src/h_matchers/matcher/collection/_mixin/contains.py index e22c9be..2797889 100644 --- a/src/h_matchers/matcher/collection/_mixin/contains.py +++ b/src/h_matchers/matcher/collection/_mixin/contains.py @@ -1,4 +1,5 @@ """A mixin for AnyCollection which lets you check for specific items.""" + from types import GeneratorType from h_matchers.decorator import fluent_entrypoint diff --git a/src/h_matchers/matcher/combination.py b/src/h_matchers/matcher/combination.py index 54934e9..2ce990c 100644 --- a/src/h_matchers/matcher/combination.py +++ b/src/h_matchers/matcher/combination.py @@ -1,4 +1,5 @@ """Matchers formed of combinations of other things.""" + from h_matchers.matcher.core import Matcher diff --git a/src/h_matchers/matcher/object.py b/src/h_matchers/matcher/object.py index 6b7f570..4c2a900 100644 --- a/src/h_matchers/matcher/object.py +++ b/src/h_matchers/matcher/object.py @@ -1,4 +1,5 @@ """Matchers for simple objects.""" + from h_matchers.decorator import fluent_entrypoint from h_matchers.matcher.core import Matcher diff --git a/src/h_matchers/matcher/web/request.py b/src/h_matchers/matcher/web/request.py index 17e675a..3540451 100644 --- a/src/h_matchers/matcher/web/request.py +++ b/src/h_matchers/matcher/web/request.py @@ -1,4 +1,5 @@ """A matcher that matches various request objects in HTTP type libraries.""" + from copy import deepcopy from h_matchers.decorator import fluent_entrypoint diff --git a/src/h_matchers/matcher/web/url/core.py b/src/h_matchers/matcher/web/url/core.py index 661ab08..a9621ee 100644 --- a/src/h_matchers/matcher/web/url/core.py +++ b/src/h_matchers/matcher/web/url/core.py @@ -57,6 +57,7 @@ Any.url(path="/foo") == "foo" # True Any.url(path="foo") == "/foo" # True """ + import re from collections import Counter from urllib.parse import parse_qsl, urlparse diff --git a/src/h_matchers/matcher/web/url/fluent.py b/src/h_matchers/matcher/web/url/fluent.py index 7129b24..907b876 100644 --- a/src/h_matchers/matcher/web/url/fluent.py +++ b/src/h_matchers/matcher/web/url/fluent.py @@ -1,4 +1,5 @@ """A fluent interface over AnyURLCore for matching URLs.""" + from h_matchers.decorator import fluent_entrypoint from h_matchers.matcher.collection import AnyMapping from h_matchers.matcher.strings import AnyString diff --git a/tests/pyproject.toml b/tests/pyproject.toml index f3a7c5e..14d9d9e 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -68,6 +68,10 @@ disable = [ # Issues to disable this for false positives, disabling it globally in the meantime https://github.com/PyCQA/pylint/issues/214 "duplicate-code", + + # Lots of false positives + "no-value-for-parameter", + ] # Just disable PyLint's name style checking for the tests, because we diff --git a/tests/unit/data_types.py b/tests/unit/data_types.py index 4869e1b..57827d5 100644 --- a/tests/unit/data_types.py +++ b/tests/unit/data_types.py @@ -1,4 +1,5 @@ """Data types for testing the matchers.""" + import enum from decimal import Decimal diff --git a/tests/unit/h_matchers/matcher/collection/_mixin/size_test.py b/tests/unit/h_matchers/matcher/collection/_mixin/size_test.py index f0e86ae..0494122 100644 --- a/tests/unit/h_matchers/matcher/collection/_mixin/size_test.py +++ b/tests/unit/h_matchers/matcher/collection/_mixin/size_test.py @@ -41,6 +41,7 @@ def test_it_complains_with_incorrect_size(self): def test_it_matches_maximum_size(self): matcher = HostClass.of_size(at_most=2) + # pylint:disable=use-implicit-booleaness-not-comparison assert matcher == [] assert matcher == [1, 2] assert matcher != [1, 2, 3] diff --git a/tests/unit/h_matchers/matcher/collection/_mixin/type_test.py b/tests/unit/h_matchers/matcher/collection/_mixin/type_test.py index 40554c6..704d7c9 100644 --- a/tests/unit/h_matchers/matcher/collection/_mixin/type_test.py +++ b/tests/unit/h_matchers/matcher/collection/_mixin/type_test.py @@ -17,6 +17,7 @@ class TestTypeMixin: def test_it_matches_specific_class(self): matcher = HostClass.of_type(list) + # pylint:disable=use-implicit-booleaness-not-comparison assert matcher == [] assert [] == matcher assert matcher != set()