Skip to content

Commit 6ce8ae8

Browse files
committed
Merge upstream master into 708-prettier-pretty
Resolved conflicts: * jsonschema/cli.py * jsonschema/exceptions.py * jsonschema/tests/test_cli.py
2 parents e64acd7 + 506cea3 commit 6ce8ae8

22 files changed

+101
-218
lines changed

.github/workflows/packaging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [macos-latest, ubuntu-latest]
14-
python-version: [pypy2, pypy3, 3.7, 3.8]
14+
python-version: [pypy3, 3.7, 3.8]
1515

1616
steps:
1717
- uses: actions/checkout@v2

docs/conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# coming with Sphinx (named "sphinx.ext.*") or your custom ones.
2626
extensions = [
2727
"sphinx.ext.autodoc",
28+
"sphinx.ext.autosectionlabel",
2829
"sphinx.ext.coverage",
2930
"sphinx.ext.doctest",
3031
"sphinx.ext.intersphinx",
@@ -88,8 +89,7 @@
8889
)
8990

9091
intersphinx_mapping = {
91-
"python": ("https://docs.python.org/2.7", None),
92-
"python3": ("https://docs.python.org/3", None),
92+
"python": ("https://docs.python.org/3", None),
9393
}
9494

9595

@@ -250,6 +250,10 @@ def entire_domain(host):
250250
"https://github.com/Julian/jsonschema/workflows/CI/badge.svg",
251251
]
252252

253+
# -- Options for sphinxcontrib-autosectionlabel ---------------------------
254+
255+
autosectionlabel_prefix_document = True
256+
253257
# -- Options for sphinxcontrib-spelling -----------------------------------
254258

255259
spelling_word_list_filename = "spelling-wordlist.txt"

docs/faq.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ notice:
222222

223223
* the contents of the ``jsonschema.benchmarks`` package
224224

225-
* the ``jsonschema.compat`` module, which is for internal
226-
compatibility use
227-
228225
* the specific non-zero error codes presented by the command line
229226
interface
230227

docs/validate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ classes should adhere to.
124124

125125
Lazily yield each of the validation errors in the given instance.
126126

127-
:rtype: an `collections.Iterable` of
127+
:rtype: an `collections.abc.Iterable` of
128128
`jsonschema.exceptions.ValidationError`\s
129129

130130
>>> schema = {

jsonschema/_format.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import socket
44
import struct
55

6-
from jsonschema.compat import str_types
76
from jsonschema.exceptions import FormatError
87

98

@@ -24,7 +23,7 @@ class FormatChecker(object):
2423
2524
Arguments:
2625
27-
formats (~collections.Iterable):
26+
formats (~collections.abc.Iterable):
2827
2928
The known formats to validate. This argument can be used to
3029
limit which formats will be used during validation.
@@ -179,7 +178,7 @@ def wrap(func):
179178
@_checks_drafts(name="idn-email")
180179
@_checks_drafts(name="email")
181180
def is_email(instance):
182-
if not isinstance(instance, str_types):
181+
if not isinstance(instance, str):
183182
return True
184183
return "@" in instance
185184

@@ -191,7 +190,7 @@ def is_email(instance):
191190
draft3="ip-address", draft4="ipv4", draft6="ipv4", draft7="ipv4",
192191
)
193192
def is_ipv4(instance):
194-
if not isinstance(instance, str_types):
193+
if not isinstance(instance, str):
195194
return True
196195
if not _ipv4_re.match(instance):
197196
return False
@@ -205,7 +204,7 @@ def is_ipv4(instance):
205204
name="ipv6", raises=(socket.error, struct.error, ValueError),
206205
)
207206
def is_ipv6(instance):
208-
if not isinstance(instance, str_types):
207+
if not isinstance(instance, str):
209208
return True
210209
return socket.inet_pton(socket.AF_INET6, instance)
211210

@@ -220,7 +219,7 @@ def is_ipv6(instance):
220219
draft7="hostname",
221220
)
222221
def is_host_name(instance):
223-
if not isinstance(instance, str_types):
222+
if not isinstance(instance, str):
224223
return True
225224
if not _host_name_re.match(instance):
226225
return False
@@ -242,7 +241,7 @@ def is_host_name(instance):
242241
raises=(idna.IDNAError, UnicodeError),
243242
)
244243
def is_idn_host_name(instance):
245-
if not isinstance(instance, str_types):
244+
if not isinstance(instance, str):
246245
return True
247246
idna.encode(instance)
248247
return True
@@ -258,7 +257,7 @@ def is_idn_host_name(instance):
258257
else:
259258
@_checks_drafts(name="uri")
260259
def is_uri(instance):
261-
if not isinstance(instance, str_types):
260+
if not isinstance(instance, str):
262261
return True
263262
return validate_rfc3986(instance, rule="URI")
264263

@@ -268,26 +267,26 @@ def is_uri(instance):
268267
raises=ValueError,
269268
)
270269
def is_uri_reference(instance):
271-
if not isinstance(instance, str_types):
270+
if not isinstance(instance, str):
272271
return True
273272
return validate_rfc3986(instance, rule="URI_reference")
274273

275274
else:
276275
@_checks_drafts(draft7="iri", raises=ValueError)
277276
def is_iri(instance):
278-
if not isinstance(instance, str_types):
277+
if not isinstance(instance, str):
279278
return True
280279
return rfc3987.parse(instance, rule="IRI")
281280

282281
@_checks_drafts(draft7="iri-reference", raises=ValueError)
283282
def is_iri_reference(instance):
284-
if not isinstance(instance, str_types):
283+
if not isinstance(instance, str):
285284
return True
286285
return rfc3987.parse(instance, rule="IRI_reference")
287286

288287
@_checks_drafts(name="uri", raises=ValueError)
289288
def is_uri(instance):
290-
if not isinstance(instance, str_types):
289+
if not isinstance(instance, str):
291290
return True
292291
return rfc3987.parse(instance, rule="URI")
293292

@@ -297,7 +296,7 @@ def is_uri(instance):
297296
raises=ValueError,
298297
)
299298
def is_uri_reference(instance):
300-
if not isinstance(instance, str_types):
299+
if not isinstance(instance, str):
301300
return True
302301
return rfc3987.parse(instance, rule="URI_reference")
303302

@@ -313,34 +312,34 @@ def is_uri_reference(instance):
313312
if validate_rfc3339:
314313
@_checks_drafts(name="date-time")
315314
def is_datetime(instance):
316-
if not isinstance(instance, str_types):
315+
if not isinstance(instance, str):
317316
return True
318317
return validate_rfc3339(instance)
319318

320319
@_checks_drafts(draft7="time")
321320
def is_time(instance):
322-
if not isinstance(instance, str_types):
321+
if not isinstance(instance, str):
323322
return True
324323
return is_datetime("1970-01-01T" + instance)
325324

326325

327326
@_checks_drafts(name="regex", raises=re.error)
328327
def is_regex(instance):
329-
if not isinstance(instance, str_types):
328+
if not isinstance(instance, str):
330329
return True
331330
return re.compile(instance)
332331

333332

334333
@_checks_drafts(draft3="date", draft7="date", raises=ValueError)
335334
def is_date(instance):
336-
if not isinstance(instance, str_types):
335+
if not isinstance(instance, str):
337336
return True
338337
return datetime.datetime.strptime(instance, "%Y-%m-%d")
339338

340339

341340
@_checks_drafts(draft3="time", raises=ValueError)
342341
def is_draft3_time(instance):
343-
if not isinstance(instance, str_types):
342+
if not isinstance(instance, str):
344343
return True
345344
return datetime.datetime.strptime(instance, "%H:%M:%S")
346345

@@ -361,7 +360,7 @@ def is_css_color_code(instance):
361360
@_checks_drafts(draft3="color", raises=(ValueError, TypeError))
362361
def is_css21_color(instance):
363362
if (
364-
not isinstance(instance, str_types) or
363+
not isinstance(instance, str) or
365364
instance.lower() in CSS21_NAMES_TO_HEX
366365
):
367366
return True
@@ -384,7 +383,7 @@ def is_css3_color(instance):
384383
raises=jsonpointer.JsonPointerException,
385384
)
386385
def is_json_pointer(instance):
387-
if not isinstance(instance, str_types):
386+
if not isinstance(instance, str):
388387
return True
389388
return jsonpointer.JsonPointer(instance)
390389

@@ -399,7 +398,7 @@ def is_json_pointer(instance):
399398
def is_relative_json_pointer(instance):
400399
# Definition taken from:
401400
# https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01#section-3
402-
if not isinstance(instance, str_types):
401+
if not isinstance(instance, str):
403402
return True
404403
non_negative_integer, rest = [], ""
405404
for i, character in enumerate(instance):

jsonschema/_legacy_validators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from jsonschema import _utils
2-
from jsonschema.compat import iteritems
32
from jsonschema.exceptions import ValidationError
43

54

65
def dependencies_draft3(validator, dependencies, instance, schema):
76
if not validator.is_type(instance, "object"):
87
return
98

10-
for property, dependency in iteritems(dependencies):
9+
for property, dependency in dependencies.items():
1110
if property not in instance:
1211
continue
1312

@@ -100,7 +99,7 @@ def properties_draft3(validator, properties, instance, schema):
10099
if not validator.is_type(instance, "object"):
101100
return
102101

103-
for property, subschema in iteritems(properties):
102+
for property, subschema in properties.items():
104103
if property in instance:
105104
for error in validator.descend(
106105
instance[property],

jsonschema/_reflect.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import sys
1111

12-
from jsonschema.compat import PY3
13-
1412

1513
class _NoModuleFound(Exception):
1614
"""
@@ -42,12 +40,8 @@ class ObjectNotFound(InvalidName):
4240

4341

4442

45-
if PY3:
46-
def reraise(exception, traceback):
47-
raise exception.with_traceback(traceback)
48-
else:
49-
exec("""def reraise(exception, traceback):
50-
raise exception.__class__, exception, traceback""")
43+
def reraise(exception, traceback):
44+
raise exception.with_traceback(traceback)
5145

5246
reraise.__doc__ = """
5347
Re-raise an exception, with an optional traceback, in a way that is compatible

jsonschema/_types.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pyrsistent import pmap
44
import attr
55

6-
from jsonschema.compat import int_types, str_types
76
from jsonschema.exceptions import UndefinedTypeCheck
87

98

@@ -19,7 +18,7 @@ def is_integer(checker, instance):
1918
# bool inherits from int, so ensure bools aren't reported as ints
2019
if isinstance(instance, bool):
2120
return False
22-
return isinstance(instance, int_types)
21+
return isinstance(instance, int)
2322

2423

2524
def is_null(checker, instance):
@@ -38,7 +37,7 @@ def is_object(checker, instance):
3837

3938

4039
def is_string(checker, instance):
41-
return isinstance(instance, str_types)
40+
return isinstance(instance, str)
4241

4342

4443
def is_any(checker, instance):
@@ -104,7 +103,7 @@ def redefine(self, type, fn):
104103
105104
The name of the type to check.
106105
107-
fn (collections.Callable):
106+
fn (collections.abc.Callable):
108107
109108
A function taking exactly two parameters - the type
110109
checker calling the function and the instance to check.
@@ -141,7 +140,7 @@ def remove(self, *types):
141140
142141
Arguments:
143142
144-
types (~collections.Iterable):
143+
types (~collections.abc.Iterable):
145144
146145
the names of the types to remove.
147146

jsonschema/_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from collections.abc import MutableMapping
2+
from urllib.parse import urlsplit
13
import itertools
24
import json
35
import pkgutil
46
import re
57

6-
from jsonschema.compat import MutableMapping, str_types, urlsplit
7-
88

99
class URIDict(MutableMapping):
1010
"""
@@ -160,7 +160,7 @@ def ensure_list(thing):
160160
Otherwise, return it unchanged.
161161
"""
162162

163-
if isinstance(thing, str_types):
163+
if isinstance(thing, str):
164164
return [thing]
165165
return thing
166166

jsonschema/_validators.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
uniq,
1111
)
1212
from jsonschema.exceptions import FormatError, ValidationError
13-
from jsonschema.compat import iteritems
1413

1514

1615
def patternProperties(validator, patternProperties, instance, schema):
1716
if not validator.is_type(instance, "object"):
1817
return
1918

20-
for pattern, subschema in iteritems(patternProperties):
21-
for k, v in iteritems(instance):
19+
for pattern, subschema in patternProperties.items():
20+
for k, v in instance.items():
2221
if re.search(pattern, k):
2322
for error in validator.descend(
2423
v, subschema, path=k, schema_path=pattern,
@@ -224,7 +223,7 @@ def dependencies(validator, dependencies, instance, schema):
224223
if not validator.is_type(instance, "object"):
225224
return
226225

227-
for property, dependency in iteritems(dependencies):
226+
for property, dependency in dependencies.items():
228227
if property not in instance:
229228
continue
230229

@@ -277,7 +276,7 @@ def properties(validator, properties, instance, schema):
277276
if not validator.is_type(instance, "object"):
278277
return
279278

280-
for property, subschema in iteritems(properties):
279+
for property, subschema in properties.items():
281280
if property in instance:
282281
for error in validator.descend(
283282
instance[property],

0 commit comments

Comments
 (0)