From e2c3a06301b119b5749968a55e494ee2cabf0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 22 Dec 2022 09:35:11 +0100 Subject: [PATCH 01/21] Add typing to some methods of ``_Error`` --- jsonschema/exceptions.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index 149d83890..e46d3defc 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -6,7 +6,7 @@ from collections import defaultdict, deque from pprint import pformat from textwrap import dedent, indent -from typing import ClassVar +from typing import TYPE_CHECKING, Any, ClassVar import heapq import itertools @@ -14,6 +14,9 @@ from jsonschema import _utils +if TYPE_CHECKING: + from jsonschema import _types + WEAK_MATCHES: frozenset[str] = frozenset(["anyOf", "oneOf"]) STRONG_MATCHES: frozenset[str] = frozenset() @@ -66,10 +69,10 @@ def __init__( for error in context: error.parent = self - def __repr__(self): + def __repr__(self) -> str: return f"<{self.__class__.__name__}: {self.message!r}>" - def __str__(self): + def __str__(self) -> str: essential_for_verbose = ( self.validator, self.validator_value, self.instance, self.schema, ) @@ -99,11 +102,11 @@ def __str__(self): ) @classmethod - def create_from(cls, other): + def create_from(cls, other: _Error): return cls(**other._contents()) @property - def absolute_path(self): + def absolute_path(self) -> deque[str | int]: parent = self.parent if parent is None: return self.relative_path @@ -113,7 +116,7 @@ def absolute_path(self): return path @property - def absolute_schema_path(self): + def absolute_schema_path(self) -> deque[str | int]: parent = self.parent if parent is None: return self.relative_schema_path @@ -123,7 +126,7 @@ def absolute_schema_path(self): return path @property - def json_path(self): + def json_path(self) -> str: path = "$" for elem in self.absolute_path: if isinstance(elem, int): @@ -132,7 +135,11 @@ def json_path(self): path += "." + elem return path - def _set(self, type_checker=None, **kwargs): + def _set( + self, + type_checker: _types.TypeChecker | None = None, + **kwargs: Any, + ) -> None: if type_checker is not None and self._type_checker is _unset: self._type_checker = type_checker @@ -188,7 +195,7 @@ class RefResolutionError(Exception): _cause = attr.ib() - def __str__(self): + def __str__(self) -> str: return str(self._cause) @@ -197,10 +204,10 @@ class UndefinedTypeCheck(Exception): A type checker was asked to check a type it did not have registered. """ - def __init__(self, type): + def __init__(self, type: str) -> None: self.type = type - def __str__(self): + def __str__(self) -> str: return f"Type {self.type!r} is unknown to this type checker" From efa28c690074fe597aea039caa8831b45cf11102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 22 Dec 2022 09:54:35 +0100 Subject: [PATCH 02/21] Add typing and check to ``_Error._matches_type`` --- jsonschema/exceptions.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index e46d3defc..c3a1aa2cd 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -154,12 +154,16 @@ def _contents(self): ) return dict((attr, getattr(self, attr)) for attr in attrs) - def _matches_type(self): + def _matches_type(self) -> bool: try: - expected = self.schema["type"] + # We ignore this as we want to simply crash if this happens + expected = self.schema["type"] # type: ignore[index] except (KeyError, TypeError): return False + if isinstance(self._type_checker, _utils.Unset): + return False + if isinstance(expected, str): return self._type_checker.is_type(self.instance, expected) From 7fd4d38f3bc124e3b493443431c85a75cabf3b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 22 Dec 2022 09:54:45 +0100 Subject: [PATCH 03/21] Add typing to ``_Error.__init__`` --- jsonschema/exceptions.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index c3a1aa2cd..29863232b 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -4,6 +4,7 @@ from __future__ import annotations from collections import defaultdict, deque +from collections.abc import Iterable, Mapping from pprint import pformat from textwrap import dedent, indent from typing import TYPE_CHECKING, Any, ClassVar @@ -31,17 +32,17 @@ class _Error(Exception): def __init__( self, message: str, - validator=_unset, - path=(), - cause=None, + validator: str | _utils.Unset = _unset, + path: Iterable[str | int] = (), + cause: Exception | None = None, context=(), validator_value=_unset, - instance=_unset, - schema=_unset, - schema_path=(), - parent=None, - type_checker=_unset, - ): + instance: Any = _unset, + schema: Mapping[str, Any] | bool | _utils.Unset = _unset, + schema_path: Iterable[str | int] = (), + parent: _Error | None = None, + type_checker: _types.TypeChecker | _utils.Unset = _unset, + ) -> None: super(_Error, self).__init__( message, validator, From 32106fd24edaae1fc3082969d3838d2c69eff670 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 19:30:30 +0000 Subject: [PATCH 04/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.2 → v0.4.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.2...v0.4.3) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 50b548389..79b6f6de3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.2" + rev: "v0.4.3" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 124d6de0ca41558b212980f26fba9291c0b09ee2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 19:26:03 +0000 Subject: [PATCH 05/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.3 → v0.4.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.3...v0.4.4) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 79b6f6de3..7f0fb2a1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.3" + rev: "v0.4.4" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 9df3ab01c275d1a6cf46a95c7b7e90942cbef162 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 20 May 2024 18:25:27 +0300 Subject: [PATCH 06/21] Update requirements. --- docs/requirements.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 6b44e8ebb..df1cb66e1 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -8,13 +8,13 @@ alabaster==0.7.16 # via sphinx anyascii==0.3.2 # via sphinx-autoapi -astroid==3.1.0 +astroid==3.2.2 # via sphinx-autoapi attrs==23.2.0 # via # jsonschema # referencing -babel==2.14.0 +babel==2.15.0 # via sphinx beautifulsoup4==4.12.3 # via furo @@ -24,13 +24,13 @@ charset-normalizer==3.3.2 # via requests docutils==0.21.2 # via sphinx -furo==2024.4.27 +furo==2024.5.6 # via -r docs/requirements.in idna==3.7 # via requests imagesize==1.4.1 # via sphinx -jinja2==3.1.3 +jinja2==3.1.4 # via # sphinx # sphinx-autoapi @@ -38,7 +38,7 @@ file:.#egg=jsonschema # via -r docs/requirements.in jsonschema-specifications==2023.12.1 # via jsonschema -lxml==5.2.1 +lxml==5.2.2 # via # -r docs/requirements.in # sphinx-json-schema-spec @@ -50,19 +50,19 @@ pyenchant==3.3.0rc1 # via # -r docs/requirements.in # sphinxcontrib-spelling -pygments==2.17.2 +pygments==2.18.0 # via # furo # sphinx pyyaml==6.0.1 # via sphinx-autoapi -referencing==0.35.0 +referencing==0.35.1 # via # jsonschema # jsonschema-specifications requests==2.31.0 # via sphinx -rpds-py==0.18.0 +rpds-py==0.18.1 # via # jsonschema # referencing From d68a2c2a59c8c4361bfce6b61c183e779b7c6b77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 May 2024 19:27:35 +0000 Subject: [PATCH 07/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.4 → v0.4.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.4...v0.4.5) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7f0fb2a1d..be5e6e1fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.4" + rev: "v0.4.5" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 6a16e61ccadf74fc7438f5d8d1d6c129a63d7d07 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 3 Jun 2024 12:00:24 +0300 Subject: [PATCH 08/21] Minor workflow trigger tweaking. --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb3b232ce..99449fd0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,12 +2,17 @@ name: CI on: push: + branches-ignore: + - "wip*" + tags: + - "v*" pull_request: release: types: [published] schedule: # Daily at 3:21 - cron: "21 3 * * *" + workflow_dispatch: env: PIP_DISABLE_PIP_VERSION_CHECK: "1" From adc71541f1e9286dd4deb4cabd5075e087ee0bc6 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 3 Jun 2024 12:01:10 +0300 Subject: [PATCH 09/21] Update docs requirements. --- docs/requirements.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index df1cb66e1..3db278783 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,8 +6,6 @@ # alabaster==0.7.16 # via sphinx -anyascii==0.3.2 - # via sphinx-autoapi astroid==3.2.2 # via sphinx-autoapi attrs==23.2.0 @@ -18,7 +16,7 @@ babel==2.15.0 # via sphinx beautifulsoup4==4.12.3 # via furo -certifi==2024.2.2 +certifi==2024.6.2 # via requests charset-normalizer==3.3.2 # via requests @@ -60,7 +58,7 @@ referencing==0.35.1 # via # jsonschema # jsonschema-specifications -requests==2.31.0 +requests==2.32.3 # via sphinx rpds-py==0.18.1 # via @@ -81,7 +79,7 @@ sphinx==7.3.7 # sphinx-json-schema-spec # sphinxcontrib-spelling # sphinxext-opengraph -sphinx-autoapi==3.0.0 +sphinx-autoapi==3.1.1 # via -r docs/requirements.in sphinx-autodoc-typehints==2.1.0 # via -r docs/requirements.in From 5c300db2a80e410aa4a9598ac64d00bd32e936a4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:35:14 +0000 Subject: [PATCH 10/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.5 → v0.4.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.5...v0.4.7) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be5e6e1fd..3a970f239 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.5" + rev: "v0.4.7" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 0151efd061d7a0dd324d83351ddfd7392dc5505f Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 5 Jun 2024 09:50:00 +0300 Subject: [PATCH 11/21] Loosen the type for error paths. --- jsonschema/exceptions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index de66e9f9c..1f1d7c011 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -17,7 +17,7 @@ from jsonschema import _utils if TYPE_CHECKING: - from collections.abc import Iterable, Mapping, MutableMapping + from collections.abc import Iterable, Mapping, MutableMapping, Sequence from jsonschema import _types @@ -121,7 +121,7 @@ def create_from(cls, other: _Error): return cls(**other._contents()) @property - def absolute_path(self) -> deque[str | int]: + def absolute_path(self) -> Sequence[str | int]: parent = self.parent if parent is None: return self.relative_path @@ -131,7 +131,7 @@ def absolute_path(self) -> deque[str | int]: return path @property - def absolute_schema_path(self) -> deque[str | int]: + def absolute_schema_path(self) -> Sequence[str | int]: parent = self.parent if parent is None: return self.relative_schema_path From 0024b584c6b6f332f0f5fa5452488901b73328f9 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 5 Jun 2024 09:58:29 +0300 Subject: [PATCH 12/21] Remove references to Unset in the typing annotations. I don't want them appearing in public documentation. The public types of these arguments do not include Unset, a user may only pass them the declared type, even though internally the type is larger. Refs: https://github.com/python-jsonschema/jsonschema/pull/1019#discussion_r1055672054 --- jsonschema/exceptions.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index 1f1d7c011..d7965468c 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -46,16 +46,16 @@ class _Error(Exception): def __init__( self, message: str, - validator: str | _utils.Unset = _unset, + validator: str = _unset, # type: ignore[assignment] path: Iterable[str | int] = (), cause: Exception | None = None, context=(), validator_value: Any = _unset, instance: Any = _unset, - schema: Mapping[str, Any] | bool | _utils.Unset = _unset, + schema: Mapping[str, Any] | bool = _unset, # type: ignore[assignment] schema_path: Iterable[str | int] = (), parent: _Error | None = None, - type_checker: _types.TypeChecker | _utils.Unset = _unset, + type_checker: _types.TypeChecker = _unset, # type: ignore[assignment] ) -> None: super().__init__( message, @@ -176,9 +176,6 @@ def _matches_type(self) -> bool: except (KeyError, TypeError): return False - if isinstance(self._type_checker, _utils.Unset): - return False - if isinstance(expected, str): return self._type_checker.is_type(self.instance, expected) From 9f7cae7f1f576b56ee93b5dc52a59e2f1c846ca6 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 9 Jun 2024 10:36:50 +0300 Subject: [PATCH 13/21] Don't reorder dicts (particularly schemas) when rendering errors. Schemas, particularly longer ones, are often written intentionally with their keywords in some specific human-understandable order. pprint, which we currently use (for better or worse) for rendering schemas and instances, supports *not* sorting dicts now that they maintain their insertion order. So we now pass that argument, and thereby preserve the order the schema was written in. Refs: #243 --- docs/errors.rst | 4 ++-- jsonschema/exceptions.py | 15 +++++++++++---- jsonschema/tests/test_exceptions.py | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/docs/errors.rst b/docs/errors.rst index 79c830e9e..9e8046ee6 100644 --- a/docs/errors.rst +++ b/docs/errors.rst @@ -216,8 +216,8 @@ easier debugging. 3 is not valid under any of the given schemas Failed validating 'anyOf' in schema['items']: - {'anyOf': [{'maxLength': 2, 'type': 'string'}, - {'minimum': 5, 'type': 'integer'}]} + {'anyOf': [{'type': 'string', 'maxLength': 2}, + {'type': 'integer', 'minimum': 5}]} On instance[1]: 3 diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index d7965468c..78da49fcd 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -27,6 +27,13 @@ _unset = _utils.Unset() +def _pretty(thing: Any, prefix: str): + """ + Format something for an error message as prettily as we currently can. + """ + return indent(pformat(thing, width=72, sort_dicts=False), prefix).lstrip() + + def __getattr__(name): if name == "RefResolutionError": warnings.warn( @@ -109,10 +116,10 @@ def __str__(self) -> str: {self.message} Failed validating {self.validator!r} in {schema_path}: - {indent(pformat(self.schema, width=72), prefix).lstrip()} + {_pretty(self.schema, prefix=prefix)} On {instance_path}: - {indent(pformat(self.instance, width=72), prefix).lstrip()} + {_pretty(self.instance, prefix=prefix)} """.rstrip(), ) @@ -278,10 +285,10 @@ def __str__(self): return dedent( f"""\ Unknown type {self.type!r} for validator with schema: - {indent(pformat(self.schema, width=72), prefix).lstrip()} + {_pretty(self.schema, prefix=prefix)} While checking instance: - {indent(pformat(self.instance, width=72), prefix).lstrip()} + {_pretty(self.instance, prefix=prefix)} """.rstrip(), ) diff --git a/jsonschema/tests/test_exceptions.py b/jsonschema/tests/test_exceptions.py index 5b3b43621..69114e182 100644 --- a/jsonschema/tests/test_exceptions.py +++ b/jsonschema/tests/test_exceptions.py @@ -648,6 +648,29 @@ def test_uses_pprint(self): validator="maxLength", ) + def test_does_not_reorder_dicts(self): + self.assertShows( + """ + Failed validating 'type' in schema: + {'do': 3, 'not': 7, 'sort': 37, 'me': 73} + + On instance: + {'here': 73, 'too': 37, 'no': 7, 'sorting': 3} + """, + schema={ + "do": 3, + "not": 7, + "sort": 37, + "me": 73, + }, + instance={ + "here": 73, + "too": 37, + "no": 7, + "sorting": 3, + }, + ) + def test_str_works_with_instances_having_overriden_eq_operator(self): """ Check for #164 which rendered exceptions unusable when a From 88a0be1dbbe2895e1fd077dc2df21b38f0af71b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:38:28 +0000 Subject: [PATCH 14/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.7 → v0.4.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.7...v0.4.8) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a970f239..2800fd595 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.7" + rev: "v0.4.8" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From a1fccdccc9e2282bdcf2fb03f8f703c30ed6b8f4 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 17 Jun 2024 16:52:40 +0200 Subject: [PATCH 15/21] Update docs requirements. --- docs/requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 3db278783..ca1958ab6 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -42,7 +42,7 @@ lxml==5.2.2 # sphinx-json-schema-spec markupsafe==2.1.5 # via jinja2 -packaging==24.0 +packaging==24.1 # via sphinx pyenchant==3.3.0rc1 # via @@ -81,7 +81,7 @@ sphinx==7.3.7 # sphinxext-opengraph sphinx-autoapi==3.1.1 # via -r docs/requirements.in -sphinx-autodoc-typehints==2.1.0 +sphinx-autodoc-typehints==2.1.1 # via -r docs/requirements.in sphinx-basic-ng==1.0.0b2 # via furo @@ -105,5 +105,5 @@ sphinxcontrib-spelling==8.0.0 # via -r docs/requirements.in sphinxext-opengraph==0.9.1 # via -r docs/requirements.in -urllib3==2.2.1 +urllib3==2.2.2 # via requests From 7fd28c3936375deb1180a45624d37c58d1576cac Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 17 Jun 2024 17:09:57 +0200 Subject: [PATCH 16/21] Update the (ancient draft3) color format for newer webcolors. Bumps the pin to the newer version, where validating these seems to now require a function call. Really we should have a better strategy in CI for ensuring we run all the format tests we intend to run, but this should happen really really rarely. Closes: ##1268 --- jsonschema/_format.py | 16 ++++++---------- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 9e4827e08..6e87620cc 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -413,20 +413,16 @@ def is_draft3_time(instance: object) -> bool: with suppress(ImportError): - from webcolors import CSS21_NAMES_TO_HEX import webcolors - def is_css_color_code(instance: object) -> bool: - return webcolors.normalize_hex(instance) - @_checks_drafts(draft3="color", raises=(ValueError, TypeError)) def is_css21_color(instance: object) -> bool: - if ( - not isinstance(instance, str) - or instance.lower() in CSS21_NAMES_TO_HEX - ): - return True - return is_css_color_code(instance) + if isinstance(instance, str): + try: + webcolors.name_to_hex(instance) + except ValueError: + webcolors.normalize_hex(instance.lower()) + return True with suppress(ImportError): diff --git a/pyproject.toml b/pyproject.toml index 45dbc8c4f..c4f7695c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ format-nongpl = [ "rfc3339-validator", "rfc3986-validator>0.1.0", "uri_template", - "webcolors>=1.11", + "webcolors>=24.6.0", ] [project.scripts] From deb53982d59d98f86ef18f50cd098066af70003e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 19:33:44 +0000 Subject: [PATCH 17/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.8 → v0.4.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.8...v0.4.9) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2800fd595..20bb33b7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.8" + rev: "v0.4.9" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From a90d6e29c65e661c22afef81d575e84a14e85cd4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:35:02 +0000 Subject: [PATCH 18/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.9 → v0.4.10](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.9...v0.4.10) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20bb33b7a..7d783dfe0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.9" + rev: "v0.4.10" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 6a00e35d5d1e304c99308e57a5fb0d7da29508fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:01:16 +0000 Subject: [PATCH 19/21] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.10 → v0.5.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.10...v0.5.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d783dfe0..a42390115 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.10" + rev: "v0.5.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 40410c45e7851816cc7f426aa6699530eb0d589e Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Mon, 8 Jul 2024 19:23:18 +0300 Subject: [PATCH 20/21] Declare support for 3.13 Fixes: https://github.com/python-jsonschema/jsonschema/issues/1264. Hardcode the `LATEST_STABLE` variable in `noxfile.py` to equal the latest stable Python release. --- .github/workflows/ci.yml | 1 + CHANGELOG.rst | 5 +++++ noxfile.py | 6 +++--- pyproject.toml | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99449fd0c..a01200b60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,7 @@ jobs: 3.10 3.11 3.12 + 3.13 pypy3.10 allow-prereleases: true - name: Set up nox diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0da30a6b5..4c7c86e1b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +v4.22.1 +======= + +* Declare support for Py3.13 + v4.22.0 ======= diff --git a/noxfile.py b/noxfile.py index 2c611278b..fada3e1f8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -35,13 +35,13 @@ "The Unlicense (Unlicense)", ] -SUPPORTED = ["3.8", "3.9", "3.10", "pypy3.10", "3.11", "3.12"] -LATEST = SUPPORTED[-1] +SUPPORTED = ["3.8", "3.9", "3.10", "pypy3.10", "3.11", "3.12", "3.13"] +LATEST_STABLE = "3.12" nox.options.sessions = [] -def session(default=True, python=LATEST, **kwargs): # noqa: D103 +def session(default=True, python=LATEST_STABLE, **kwargs): # noqa: D103 def _session(fn): if default: nox.options.sessions.append(kwargs.get("name", fn.__name__)) diff --git a/pyproject.toml b/pyproject.toml index c4f7695c0..1eea228f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: File Formats :: JSON", From cfe8a4071672b9652c8f083faed1c4ffa7d67705 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 8 Jul 2024 13:42:11 -0400 Subject: [PATCH 21/21] Document the other change, and call this 4.23.0. --- CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4c7c86e1b..a7b9d86eb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,7 @@ -v4.22.1 +v4.23.0 ======= +* Do not reorder dictionaries (schemas, instances) that are printed as part of validation errors. * Declare support for Py3.13 v4.22.0