diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 240d9595..fccb2200 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.1.14" + rev: "v0.2.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/jsonschema/_format.py b/jsonschema/_format.py index e5f5bb7c..9e4827e0 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -40,6 +40,7 @@ class FormatChecker: The known formats to validate. This argument can be used to limit which formats will be used during validation. + """ checkers: dict[ @@ -75,6 +76,7 @@ def checks( The exception object will be accessible as the `jsonschema.exceptions.ValidationError.cause` attribute of the resulting validation error. + """ def _checks(func: _F) -> _F: @@ -127,6 +129,7 @@ def check(self, instance: object, format: str) -> None: FormatError: if the instance does not conform to ``format`` + """ if format not in self.checkers: return @@ -157,6 +160,7 @@ def conforms(self, instance: object, format: str) -> bool: Returns: bool: whether it conformed + """ try: self.check(instance, format) diff --git a/jsonschema/_types.py b/jsonschema/_types.py index 5c8930c1..bf25e7e6 100644 --- a/jsonschema/_types.py +++ b/jsonschema/_types.py @@ -76,6 +76,7 @@ class TypeChecker: type_checkers: The initial mapping of types to their checking functions. + """ _type_checkers: HashTrieMap[ @@ -105,6 +106,7 @@ def is_type(self, instance, type: str) -> bool: `jsonschema.exceptions.UndefinedTypeCheck`: if ``type`` is unknown to this object. + """ try: fn = self._type_checkers[type] @@ -129,6 +131,7 @@ def redefine(self, type: str, fn) -> TypeChecker: checker calling the function and the instance to check. The function should return true if instance is of this type and false otherwise. + """ return self.redefine_many({type: fn}) @@ -141,6 +144,7 @@ def redefine_many(self, definitions=()) -> TypeChecker: definitions (dict): A dictionary mapping types to their checking functions. + """ type_checkers = self._type_checkers.update(definitions) return evolve(self, type_checkers=type_checkers) @@ -160,6 +164,7 @@ def remove(self, *types) -> TypeChecker: `jsonschema.exceptions.UndefinedTypeCheck`: if any given type is unknown to this object + """ type_checkers = self._type_checkers for each in types: diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 57fddc49..8451bb83 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -59,6 +59,7 @@ def format_as_index(container, indices): indices (sequence): The indices to format. + """ if not indices: return container diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index 7caa432e..ace9df61 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -390,6 +390,7 @@ def by_relevance(weak=WEAK_MATCHES, strong=STRONG_MATCHES): strong (set): a collection of validation keywords to consider to be "strong" + """ def relevance(error): @@ -453,6 +454,7 @@ def best_match(errors, key=relevance): This function is a heuristic. Its return value may change for a given set of inputs from version to version if better heuristics are added. + """ errors = iter(errors) best = next(errors, None) diff --git a/jsonschema/protocols.py b/jsonschema/protocols.py index 43b64c6c..39e56d0f 100644 --- a/jsonschema/protocols.py +++ b/jsonschema/protocols.py @@ -86,6 +86,7 @@ class Validator(Protocol): Subclassing validator classes now explicitly warns this is not part of their public API. + """ #: An object representing the validator's meta schema (the schema that @@ -129,6 +130,7 @@ def check_schema(cls, schema: Mapping | bool) -> None: `jsonschema.exceptions.SchemaError`: if the schema is invalid + """ def is_type(self, instance: Any, type: str) -> bool: @@ -154,6 +156,7 @@ def is_type(self, instance: Any, type: str) -> bool: `jsonschema.exceptions.UnknownType`: if ``type`` is not a known type + """ def is_valid(self, instance: Any) -> bool: @@ -167,6 +170,7 @@ def is_valid(self, instance: Any) -> bool: >>> schema = {"maxItems" : 2} >>> Draft202012Validator(schema).is_valid([2, 3, 4]) False + """ def iter_errors(self, instance: Any) -> Iterable[ValidationError]: @@ -205,6 +209,7 @@ def validate(self, instance: Any) -> None: Traceback (most recent call last): ... ValidationError: [2, 3, 4] is too long + """ def evolve(self, **kwargs) -> Validator: diff --git a/jsonschema/validators.py b/jsonschema/validators.py index fefbe832..283fe359 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -95,6 +95,7 @@ def validates(version): collections.abc.Callable: a class decorator to decorate the validator with the version + """ def _validates(cls): @@ -209,6 +210,7 @@ def create( Returns: a new `jsonschema.protocols.Validator` class + """ # preemptively don't shadow the `Validator.format_checker` local format_checker_arg = format_checker @@ -566,6 +568,7 @@ def extend( class. Note that no implicit copying is done, so a copy should likely be made before modifying it, in order to not affect the old validator. + """ all_validators = dict(validator.VALIDATORS) all_validators.update(validators) @@ -892,6 +895,7 @@ class _RefResolver: .. deprecated:: v4.18.0 ``RefResolver`` has been deprecated in favor of `referencing`. + """ _DEPRECATION_MESSAGE = ( @@ -961,6 +965,7 @@ def from_schema( # noqa: D417 Returns: `_RefResolver` + """ return cls(base_uri=id_of(schema) or "", referrer=schema, *args, **kwargs) # noqa: B026, E501 @@ -1040,6 +1045,7 @@ def resolving(self, ref): ref (str): The reference to resolve + """ url, resolved = self.resolve(ref) self.push_scope(url) @@ -1121,6 +1127,7 @@ def resolve_fragment(self, document, fragment): fragment (str): a URI fragment to resolve within it + """ fragment = fragment.lstrip("/") @@ -1190,6 +1197,7 @@ def resolve_remote(self, uri): The retrieved document .. _requests: https://pypi.org/project/requests/ + """ try: import requests @@ -1301,6 +1309,7 @@ def validate(instance, schema, cls=None, *args, **kwargs): # noqa: D417 .. rubric:: Footnotes .. [#] known by a validator registered with `jsonschema.validators.validates` + """ if cls is None: cls = validator_for(schema)