Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #1219

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -157,6 +160,7 @@ def conforms(self, instance: object, format: str) -> bool:
Returns:

bool: whether it conformed

"""
try:
self.check(instance, format)
Expand Down
5 changes: 5 additions & 0 deletions jsonschema/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TypeChecker:
type_checkers:

The initial mapping of types to their checking functions.

"""

_type_checkers: HashTrieMap[
Expand Down Expand Up @@ -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]
Expand All @@ -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})

Expand All @@ -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)
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions jsonschema/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def format_as_index(container, indices):
indices (sequence):

The indices to format.

"""
if not indices:
return container
Expand Down
2 changes: 2 additions & 0 deletions jsonschema/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions jsonschema/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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]:
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def validates(version):
collections.abc.Callable:

a class decorator to decorate the validator with the version

"""

def _validates(cls):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -892,6 +895,7 @@ class _RefResolver:
.. deprecated:: v4.18.0

``RefResolver`` has been deprecated in favor of `referencing`.

"""

_DEPRECATION_MESSAGE = (
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1040,6 +1045,7 @@ def resolving(self, ref):
ref (str):

The reference to resolve

"""
url, resolved = self.resolve(ref)
self.push_scope(url)
Expand Down Expand Up @@ -1121,6 +1127,7 @@ def resolve_fragment(self, document, fragment):
fragment (str):

a URI fragment to resolve within it

"""
fragment = fragment.lstrip("/")

Expand Down Expand Up @@ -1190,6 +1197,7 @@ def resolve_remote(self, uri):
The retrieved document

.. _requests: https://pypi.org/project/requests/

"""
try:
import requests
Expand Down Expand Up @@ -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)
Expand Down
Loading