From d8744fe9f1aaf1790fd53c2b39e230500bd36d36 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 28 Jul 2023 16:59:15 +0200 Subject: [PATCH] Enable another ruff ruleset. --- jsonschema/_format.py | 6 +++--- jsonschema/tests/test_deprecations.py | 26 +++++++++++++------------- jsonschema/tests/test_validators.py | 4 ++-- jsonschema/validators.py | 4 ++-- pyproject.toml | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 2231f5e05..f9f82bbe4 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -45,7 +45,7 @@ class FormatChecker: checkers: dict[ str, tuple[_FormatCheckCallable, _RaisesType], - ] = {} + ] = {} # noqa: RUF012 def __init__(self, formats: typing.Iterable[str] | None = None): if formats is None: @@ -55,7 +55,7 @@ def __init__(self, formats: typing.Iterable[str] | None = None): def __repr__(self): return f"" - def checks( # noqa: D417,D214,D405 (charliermarsh/ruff#3547) + def checks( # noqa: D417 self, format: str, raises: _RaisesType = (), ) -> typing.Callable[[_F], _F]: """ @@ -75,7 +75,7 @@ def checks( # noqa: D417,D214,D405 (charliermarsh/ruff#3547) The exception object will be accessible as the `jsonschema.exceptions.ValidationError.cause` attribute of the resulting validation error. - """ # noqa: D417,D214,D405 (charliermarsh/ruff#3547) + """ # noqa: D214,D405 (charliermarsh/ruff#3547) def _checks(func: _F) -> _F: self.checkers[format] = (func, raises) diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py index 85927e695..de2279c2b 100644 --- a/jsonschema/tests/test_deprecations.py +++ b/jsonschema/tests/test_deprecations.py @@ -16,7 +16,7 @@ def test_version(self): message = "Accessing jsonschema.__version__ is deprecated" with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import __version__ # noqa + from jsonschema import __version__ # noqa: F401 self.assertEqual(w.filename, __file__) @@ -28,7 +28,7 @@ def test_validators_ErrorTree(self): message = "Importing ErrorTree from jsonschema.validators is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema.validators import ErrorTree # noqa + from jsonschema.validators import ErrorTree self.assertEqual(ErrorTree, exceptions.ErrorTree) self.assertEqual(w.filename, __file__) @@ -41,7 +41,7 @@ def test_import_ErrorTree(self): message = "Importing ErrorTree directly from the jsonschema package " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import ErrorTree # noqa + from jsonschema import ErrorTree self.assertEqual(ErrorTree, exceptions.ErrorTree) self.assertEqual(w.filename, __file__) @@ -54,7 +54,7 @@ def test_import_FormatError(self): message = "Importing FormatError directly from the jsonschema package " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import FormatError # noqa + from jsonschema import FormatError self.assertEqual(FormatError, exceptions.FormatError) self.assertEqual(w.filename, __file__) @@ -145,7 +145,7 @@ def test_RefResolver(self): message = "jsonschema.RefResolver is deprecated" with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import RefResolver # noqa: F401 + from jsonschema import RefResolver self.assertEqual(w.filename, __file__) with self.assertWarnsRegex(DeprecationWarning, message) as w: @@ -160,13 +160,13 @@ def test_RefResolutionError(self): message = "jsonschema.exceptions.RefResolutionError is deprecated" with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import RefResolutionError # noqa: F401 + from jsonschema import RefResolutionError self.assertEqual(RefResolutionError, exceptions._RefResolutionError) self.assertEqual(w.filename, __file__) with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema.exceptions import RefResolutionError # noqa + from jsonschema.exceptions import RefResolutionError self.assertEqual(RefResolutionError, exceptions._RefResolutionError) self.assertEqual(w.filename, __file__) @@ -274,7 +274,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft202012_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft202012_format_checker # noqa + from jsonschema import draft202012_format_checker self.assertIs( draft202012_format_checker, @@ -284,7 +284,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft201909_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft201909_format_checker # noqa + from jsonschema import draft201909_format_checker self.assertIs( draft201909_format_checker, @@ -294,7 +294,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft7_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft7_format_checker # noqa + from jsonschema import draft7_format_checker self.assertIs( draft7_format_checker, @@ -304,7 +304,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft6_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft6_format_checker # noqa + from jsonschema import draft6_format_checker self.assertIs( draft6_format_checker, @@ -314,7 +314,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft4_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft4_format_checker # noqa + from jsonschema import draft4_format_checker self.assertIs( draft4_format_checker, @@ -324,7 +324,7 @@ def test_draftN_format_checker(self): message = "Accessing jsonschema.draft3_format_checker is " with self.assertWarnsRegex(DeprecationWarning, message) as w: - from jsonschema import draft3_format_checker # noqa + from jsonschema import draft3_format_checker self.assertIs( draft3_format_checker, diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 940a86da4..a15c8ff7b 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -2393,7 +2393,7 @@ def test_pointer_within_schema_with_different_id(self): def test_newly_created_validator_with_ref_resolver(self): """ See https://github.com/python-jsonschema/jsonschema/issues/1061#issuecomment-1624266555. - """ # noqa: E501 + """ def handle(uri): self.assertEqual(uri, "http://example.com/foo") @@ -2414,7 +2414,7 @@ def handle(uri): def test_refresolver_with_pointer_in_schema_with_no_id(self): """ See https://github.com/python-jsonschema/jsonschema/issues/1124#issuecomment-1632574249. - """ # noqa: E501 + """ schema = { "properties": {"x": {"$ref": "#/definitions/x"}}, diff --git a/jsonschema/validators.py b/jsonschema/validators.py index d5b4fcda8..850a1de68 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -213,8 +213,8 @@ def create( @define class Validator: - VALIDATORS = dict(validators) - META_SCHEMA = dict(meta_schema) + VALIDATORS = dict(validators) # noqa: RUF012 + META_SCHEMA = dict(meta_schema) # noqa: RUF012 TYPE_CHECKER = type_checker FORMAT_CHECKER = format_checker_arg ID_OF = staticmethod(id_of) diff --git a/pyproject.toml b/pyproject.toml index 674684dee..d351619b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,7 +141,7 @@ exclude = ["jsonschema/benchmarks/*"] [tool.ruff] line-length = 79 target-version = "py38" -select = ["B", "D", "D204", "E", "F", "Q", "SIM", "UP", "W"] +select = ["B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "UP", "W"] ignore = [ # Wat, type annotations for self and cls, why is this a thing? "ANN101", @@ -182,4 +182,4 @@ docstring-quotes = "double" "jsonschema/cli.py" = ["D", "SIM", "UP"] "jsonschema/_utils.py" = ["D"] "jsonschema/benchmarks/*" = ["D"] -"jsonschema/tests/*" = ["ANN", "D", "SIM"] +"jsonschema/tests/*" = ["ANN", "D", "RUF012", "SIM"]