Skip to content

Commit ea1c71a

Browse files
committed
Merge remote-tracking branch 'origin/main' into docs/autodoc
* origin/main: Remove noise from the Sphinx config. Fix instantiating validators with cached refs-to-bool schemas. Try fixing more Sphinx refs which fail only on Ubuntu...
2 parents 1aafa19 + 2815178 commit ea1c71a

File tree

6 files changed

+72
-113
lines changed

6 files changed

+72
-113
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v4.17.3
2+
=======
3+
4+
* Fix instantiating validators with cached refs to boolean schemas
5+
rather than objects (#1018).
6+
17
v4.17.2
28
=======
39

docs/conf.py

Lines changed: 42 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,16 @@
55
ROOT = Path(__file__).parent.parent
66
PACKAGE_SRC = ROOT / "jsonschema"
77

8-
# -- Project information -----------------------------------------------------
9-
108
project = "jsonschema"
119
author = "Julian Berman"
1210
copyright = "2013, " + author
1311

14-
# version: The short X.Y version
15-
# release: The full version, including alpha/beta/rc tags.
1612
release = importlib.metadata.version("jsonschema")
1713
version = release.partition("-")[0]
1814

19-
20-
# -- General configuration ---------------------------------------------------
21-
22-
# If your documentation needs a minimal Sphinx version, state it here.
23-
#
24-
# needs_sphinx = "1.0"
25-
15+
language = "en"
2616
default_role = "any"
2717

28-
# Add any Sphinx extension module names here, as strings. They can be
29-
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
30-
# ones.
3118
extensions = [
3219
"sphinx.ext.autodoc",
3320
"sphinx.ext.autosectionlabel",
@@ -42,104 +29,18 @@
4229
"sphinxext.opengraph",
4330
]
4431

45-
# Add typing annotations to signatures
46-
autodoc_typehints = "signature"
47-
4832
cache_path = "_cache"
4933

50-
# Add any paths that contain templates here, relative to this directory.
51-
templates_path = ["_templates"]
52-
53-
# The suffix(es) of source filenames.
54-
# You can specify multiple suffix as a list of string:
55-
#
56-
# source_suffix = [".rst", ".md"]
57-
source_suffix = ".rst"
58-
59-
# The master toctree document.
60-
master_doc = "index"
61-
62-
# There are two options for replacing |today|: either, you set today to some
63-
# non-false value, then it is used:
64-
# today = ""
65-
# Else, today_fmt is used as the format for a strftime call.
66-
# today_fmt = "%B %d, %Y"
67-
68-
# List of patterns, relative to source directory, that match files and
69-
# directories to ignore when looking for source files.
70-
# This pattern also affects html_static_path and html_extra_path.
71-
exclude_patterns = ["_build", "_cache", "_static", "_templates"]
72-
73-
# The name of the Pygments (syntax highlighting) style to use.
7434
pygments_style = "lovelace"
7535
pygments_dark_style = "one-dark"
7636

77-
doctest_global_setup = """
78-
from jsonschema import *
79-
"""
80-
81-
intersphinx_mapping = {
82-
"python": ("https://docs.python.org/3", None),
83-
"ujs": ("https://json-schema.org/understanding-json-schema/", None),
84-
}
85-
86-
87-
# -- Options for HTML output -----------------------------------------------
88-
89-
# The theme to use for HTML and HTML Help pages. See the documentation for
90-
# a list of builtin themes.
9137
html_theme = "furo"
9238

93-
# Theme options are theme-specific and customize the look and feel of a theme
94-
# further. For a list of options available for each theme, see the
95-
# documentation.
96-
#
97-
# html_theme_options = {}
98-
99-
# Add any paths that contain custom static files (such as style sheets) here,
100-
# relative to this directory. They are copied after the builtin static files,
101-
# so a file named "default.css" will overwrite the builtin "default.css".
102-
# html_static_path = ["_static"]
103-
104-
105-
# -- Options for HTMLHelp output ---------------------------------------------
106-
107-
# Output file base name for HTML help builder.
108-
htmlhelp_basename = "jsonschemadoc"
109-
39+
# = Builders =
11040

111-
# -- Options for LaTeX output ------------------------------------------------
112-
113-
latex_documents = [
114-
("index", "jsonschema.tex", "jsonschema Documentation", author, "manual"),
115-
]
116-
117-
118-
# -- Options for manual page output ------------------------------------------
119-
120-
# One entry per manual page. List of tuples
121-
# (source start file, name, description, authors, manual section).
122-
man_pages = [("index", "jsonschema", "jsonschema Documentation", [author], 1)]
123-
124-
125-
# -- Options for Texinfo output ----------------------------------------------
126-
127-
# Grouping the document tree into Texinfo files. List of tuples
128-
# (source start file, target name, title, author,
129-
# dir menu entry, description, category)
130-
texinfo_documents = [
131-
(
132-
"index",
133-
"jsonschema",
134-
"jsonschema Documentation",
135-
author,
136-
"jsonschema",
137-
"One line description of project.",
138-
"Miscellaneous",
139-
),
140-
]
141-
142-
# -- Options for the linkcheck builder --------------------------------------
41+
doctest_global_setup = """
42+
from jsonschema import *
43+
"""
14344

14445

14546
def entire_domain(host):
@@ -152,10 +53,45 @@ def entire_domain(host):
15253
"https://github.com/python-jsonschema/jsonschema/workflows/CI/badge.svg",
15354
]
15455

155-
# -- Options for sphinxcontrib-autosectionlabel ---------------------------
56+
# = Extensions =
57+
58+
# -- autoapi --
59+
60+
suppress_warnings = [
61+
"autoapi.python_import_resolution",
62+
"autoapi.toc_reference",
63+
"epub.duplicated_toc_entry",
64+
]
65+
autoapi_root = "api"
66+
autoapi_ignore = [
67+
"*/_[a-z]*.py",
68+
"*/__main__.py",
69+
"*/benchmarks/*",
70+
"*/cli.py",
71+
"*/tests/*",
72+
]
73+
autoapi_options = [
74+
"members",
75+
"undoc-members",
76+
"show-module-summary",
77+
"imported-members",
78+
]
79+
80+
autoapi_type = "python"
81+
autoapi_dirs = [PACKAGE_SRC]
82+
83+
# -- autosectionlabel --
15684

15785
autosectionlabel_prefix_document = True
15886

159-
# -- Options for sphinxcontrib-spelling -----------------------------------
87+
# -- intersphinx --
88+
89+
intersphinx_mapping = {
90+
"python": ("https://docs.python.org/3", None),
91+
"ujs": ("https://json-schema.org/understanding-json-schema/", None),
92+
}
93+
94+
# -- sphinxcontrib-spelling --
16095

16196
spelling_word_list_filename = "spelling-wordlist.txt"
97+
spelling_show_suggestions = True

docs/validate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The Basics
1616
----------
1717

1818
The simplest way to validate an instance under a given schema is to use the
19-
:func:`validate` function.
19+
`validate <jsonschema.validators.validate>` function.
2020

2121
.. autofunction:: validate
2222
:noindex:

jsonschema/protocols.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# but use `jsonschema` for any types which will otherwise not be resolvable
3030
if TYPE_CHECKING:
3131
import jsonschema
32+
import jsonschema.validators
3233

3334
from jsonschema.exceptions import ValidationError
3435

@@ -107,7 +108,7 @@ class Validator(Protocol):
107108
def __init__(
108109
self,
109110
schema: Mapping | bool,
110-
resolver: jsonschema.RefResolver | None = None,
111+
resolver: jsonschema.validators.RefResolver | None = None,
111112
format_checker: jsonschema.FormatChecker | None = None,
112113
) -> None:
113114
...

jsonschema/tests/test_validators.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,21 @@ class TestDraft202012Validator(ValidatorTestMixin, TestCase):
18481848
invalid = {"type": "integer"}, "foo"
18491849

18501850

1851+
class TestLatestValidator(TestCase):
1852+
"""
1853+
These really apply to multiple versions but are easiest to test on one.
1854+
"""
1855+
1856+
def test_ref_resolvers_may_have_boolean_schemas_stored(self):
1857+
ref = "someCoolRef"
1858+
schema = {"$ref": ref}
1859+
resolver = validators.RefResolver("", {}, store={ref: False})
1860+
validator = validators._LATEST_VERSION(schema, resolver=resolver)
1861+
1862+
with self.assertRaises(exceptions.ValidationError):
1863+
validator.validate(None)
1864+
1865+
18511866
class TestValidatorFor(TestCase):
18521867
def test_draft_3(self):
18531868
schema = {"$schema": "http://json-schema.org/draft-03/schema"}

jsonschema/validators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from __future__ import annotations
55

66
from collections import deque
7-
from collections.abc import Sequence
7+
from collections.abc import Mapping, Sequence
88
from functools import lru_cache
99
from operator import methodcaller
1010
from urllib.parse import unquote, urldefrag, urljoin, urlsplit
@@ -745,7 +745,8 @@ def __init__(
745745
self.store.update(store)
746746
self.store.update(
747747
(schema["$id"], schema)
748-
for schema in store.values() if "$id" in schema
748+
for schema in store.values()
749+
if isinstance(schema, Mapping) and "$id" in schema
749750
)
750751
self.store[base_uri] = referrer
751752

@@ -1060,9 +1061,9 @@ def validate(instance, schema, cls=None, *args, **kwargs):
10601061
...
10611062
ValidationError: [2, 3, 4] is too long
10621063
1063-
:func:`validate` will first verify that the provided schema is
1064-
itself valid, since not doing so can lead to less obvious error
1065-
messages and fail in less obvious or consistent ways.
1064+
:func:`~jsonschema.validators.validate` will first verify that the
1065+
provided schema is itself valid, since not doing so can lead to less
1066+
obvious error messages and fail in less obvious or consistent ways.
10661067
10671068
If you know you have a valid schema already, especially
10681069
if you intend to validate multiple instances with

0 commit comments

Comments
 (0)