Skip to content

Commit

Permalink
Merge upstream master into 708-prettier-pretty
Browse files Browse the repository at this point in the history
Resolved conflicts:
* jsonschema/cli.py
* jsonschema/exceptions.py
* jsonschema/tests/test_cli.py
  • Loading branch information
sloanlance committed Aug 7, 2020
2 parents e64acd7 + 506cea3 commit 6ce8ae8
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
python-version: [pypy2, pypy3, 3.7, 3.8]
python-version: [pypy3, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# coming with Sphinx (named "sphinx.ext.*") or your custom ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosectionlabel",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
Expand Down Expand Up @@ -88,8 +89,7 @@
)

intersphinx_mapping = {
"python": ("https://docs.python.org/2.7", None),
"python3": ("https://docs.python.org/3", None),
"python": ("https://docs.python.org/3", None),
}


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

# -- Options for sphinxcontrib-autosectionlabel ---------------------------

autosectionlabel_prefix_document = True

# -- Options for sphinxcontrib-spelling -----------------------------------

spelling_word_list_filename = "spelling-wordlist.txt"
3 changes: 0 additions & 3 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ notice:

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

* the ``jsonschema.compat`` module, which is for internal
compatibility use

* the specific non-zero error codes presented by the command line
interface

Expand Down
2 changes: 1 addition & 1 deletion docs/validate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ classes should adhere to.

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

:rtype: an `collections.Iterable` of
:rtype: an `collections.abc.Iterable` of
`jsonschema.exceptions.ValidationError`\s

>>> schema = {
Expand Down
41 changes: 20 additions & 21 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import socket
import struct

from jsonschema.compat import str_types
from jsonschema.exceptions import FormatError


Expand All @@ -24,7 +23,7 @@ class FormatChecker(object):
Arguments:
formats (~collections.Iterable):
formats (~collections.abc.Iterable):
The known formats to validate. This argument can be used to
limit which formats will be used during validation.
Expand Down Expand Up @@ -179,7 +178,7 @@ def wrap(func):
@_checks_drafts(name="idn-email")
@_checks_drafts(name="email")
def is_email(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return "@" in instance

Expand All @@ -191,7 +190,7 @@ def is_email(instance):
draft3="ip-address", draft4="ipv4", draft6="ipv4", draft7="ipv4",
)
def is_ipv4(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
if not _ipv4_re.match(instance):
return False
Expand All @@ -205,7 +204,7 @@ def is_ipv4(instance):
name="ipv6", raises=(socket.error, struct.error, ValueError),
)
def is_ipv6(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return socket.inet_pton(socket.AF_INET6, instance)

Expand All @@ -220,7 +219,7 @@ def is_ipv6(instance):
draft7="hostname",
)
def is_host_name(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
if not _host_name_re.match(instance):
return False
Expand All @@ -242,7 +241,7 @@ def is_host_name(instance):
raises=(idna.IDNAError, UnicodeError),
)
def is_idn_host_name(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
idna.encode(instance)
return True
Expand All @@ -258,7 +257,7 @@ def is_idn_host_name(instance):
else:
@_checks_drafts(name="uri")
def is_uri(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return validate_rfc3986(instance, rule="URI")

Expand All @@ -268,26 +267,26 @@ def is_uri(instance):
raises=ValueError,
)
def is_uri_reference(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return validate_rfc3986(instance, rule="URI_reference")

else:
@_checks_drafts(draft7="iri", raises=ValueError)
def is_iri(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return rfc3987.parse(instance, rule="IRI")

@_checks_drafts(draft7="iri-reference", raises=ValueError)
def is_iri_reference(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return rfc3987.parse(instance, rule="IRI_reference")

@_checks_drafts(name="uri", raises=ValueError)
def is_uri(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return rfc3987.parse(instance, rule="URI")

Expand All @@ -297,7 +296,7 @@ def is_uri(instance):
raises=ValueError,
)
def is_uri_reference(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return rfc3987.parse(instance, rule="URI_reference")

Expand All @@ -313,34 +312,34 @@ def is_uri_reference(instance):
if validate_rfc3339:
@_checks_drafts(name="date-time")
def is_datetime(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return validate_rfc3339(instance)

@_checks_drafts(draft7="time")
def is_time(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return is_datetime("1970-01-01T" + instance)


@_checks_drafts(name="regex", raises=re.error)
def is_regex(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return re.compile(instance)


@_checks_drafts(draft3="date", draft7="date", raises=ValueError)
def is_date(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return datetime.datetime.strptime(instance, "%Y-%m-%d")


@_checks_drafts(draft3="time", raises=ValueError)
def is_draft3_time(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return datetime.datetime.strptime(instance, "%H:%M:%S")

Expand All @@ -361,7 +360,7 @@ def is_css_color_code(instance):
@_checks_drafts(draft3="color", raises=(ValueError, TypeError))
def is_css21_color(instance):
if (
not isinstance(instance, str_types) or
not isinstance(instance, str) or
instance.lower() in CSS21_NAMES_TO_HEX
):
return True
Expand All @@ -384,7 +383,7 @@ def is_css3_color(instance):
raises=jsonpointer.JsonPointerException,
)
def is_json_pointer(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return jsonpointer.JsonPointer(instance)

Expand All @@ -399,7 +398,7 @@ def is_json_pointer(instance):
def is_relative_json_pointer(instance):
# Definition taken from:
# https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01#section-3
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
non_negative_integer, rest = [], ""
for i, character in enumerate(instance):
Expand Down
5 changes: 2 additions & 3 deletions jsonschema/_legacy_validators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from jsonschema import _utils
from jsonschema.compat import iteritems
from jsonschema.exceptions import ValidationError


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

for property, dependency in iteritems(dependencies):
for property, dependency in dependencies.items():
if property not in instance:
continue

Expand Down Expand Up @@ -100,7 +99,7 @@ def properties_draft3(validator, properties, instance, schema):
if not validator.is_type(instance, "object"):
return

for property, subschema in iteritems(properties):
for property, subschema in properties.items():
if property in instance:
for error in validator.descend(
instance[property],
Expand Down
10 changes: 2 additions & 8 deletions jsonschema/_reflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import sys

from jsonschema.compat import PY3


class _NoModuleFound(Exception):
"""
Expand Down Expand Up @@ -42,12 +40,8 @@ class ObjectNotFound(InvalidName):



if PY3:
def reraise(exception, traceback):
raise exception.with_traceback(traceback)
else:
exec("""def reraise(exception, traceback):
raise exception.__class__, exception, traceback""")
def reraise(exception, traceback):
raise exception.with_traceback(traceback)

reraise.__doc__ = """
Re-raise an exception, with an optional traceback, in a way that is compatible
Expand Down
9 changes: 4 additions & 5 deletions jsonschema/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pyrsistent import pmap
import attr

from jsonschema.compat import int_types, str_types
from jsonschema.exceptions import UndefinedTypeCheck


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


def is_null(checker, instance):
Expand All @@ -38,7 +37,7 @@ def is_object(checker, instance):


def is_string(checker, instance):
return isinstance(instance, str_types)
return isinstance(instance, str)


def is_any(checker, instance):
Expand Down Expand Up @@ -104,7 +103,7 @@ def redefine(self, type, fn):
The name of the type to check.
fn (collections.Callable):
fn (collections.abc.Callable):
A function taking exactly two parameters - the type
checker calling the function and the instance to check.
Expand Down Expand Up @@ -141,7 +140,7 @@ def remove(self, *types):
Arguments:
types (~collections.Iterable):
types (~collections.abc.Iterable):
the names of the types to remove.
Expand Down
6 changes: 3 additions & 3 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections.abc import MutableMapping
from urllib.parse import urlsplit
import itertools
import json
import pkgutil
import re

from jsonschema.compat import MutableMapping, str_types, urlsplit


class URIDict(MutableMapping):
"""
Expand Down Expand Up @@ -160,7 +160,7 @@ def ensure_list(thing):
Otherwise, return it unchanged.
"""

if isinstance(thing, str_types):
if isinstance(thing, str):
return [thing]
return thing

Expand Down
9 changes: 4 additions & 5 deletions jsonschema/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
uniq,
)
from jsonschema.exceptions import FormatError, ValidationError
from jsonschema.compat import iteritems


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

for pattern, subschema in iteritems(patternProperties):
for k, v in iteritems(instance):
for pattern, subschema in patternProperties.items():
for k, v in instance.items():
if re.search(pattern, k):
for error in validator.descend(
v, subschema, path=k, schema_path=pattern,
Expand Down Expand Up @@ -224,7 +223,7 @@ def dependencies(validator, dependencies, instance, schema):
if not validator.is_type(instance, "object"):
return

for property, dependency in iteritems(dependencies):
for property, dependency in dependencies.items():
if property not in instance:
continue

Expand Down Expand Up @@ -277,7 +276,7 @@ def properties(validator, properties, instance, schema):
if not validator.is_type(instance, "object"):
return

for property, subschema in iteritems(properties):
for property, subschema in properties.items():
if property in instance:
for error in validator.descend(
instance[property],
Expand Down
Loading

0 comments on commit 6ce8ae8

Please sign in to comment.