Skip to content

Commit

Permalink
pre-commit autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Mar 16, 2024
1 parent c306e2e commit d129b1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 24.2.0
rev: 24.3.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
26 changes: 5 additions & 21 deletions src/attr/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ def __call__(self, inst, attr, value):
We use a callable class to be able to change the ``__repr__``.
"""
if not isinstance(value, self.type):
msg = "'{name}' must be {type!r} (got {value!r} that is a {actual!r}).".format(
name=attr.name,
type=self.type,
actual=value.__class__,
value=value,
)
msg = f"'{attr.name}' must be {self.type!r} (got {value!r} that is a {value.__class__!r})."
raise TypeError(
msg,
attr,
Expand Down Expand Up @@ -140,9 +135,7 @@ def __call__(self, inst, attr, value):
We use a callable class to be able to change the ``__repr__``.
"""
if not self.match_func(value):
msg = "'{name}' must match regex {pattern!r} ({value!r} doesn't)".format(
name=attr.name, pattern=self.pattern.pattern, value=value
)
msg = f"'{attr.name}' must match regex {self.pattern.pattern!r} ({value!r} doesn't)"
raise ValueError(
msg,
attr,
Expand Down Expand Up @@ -206,9 +199,7 @@ def __call__(self, inst, attr, value):
We use a callable class to be able to change the ``__repr__``.
"""
if not self.interface.providedBy(value):
msg = "'{name}' must provide {interface!r} which {value!r} doesn't.".format(
name=attr.name, interface=self.interface, value=value
)
msg = f"'{attr.name}' must provide {self.interface!r} which {value!r} doesn't."
raise TypeError(
msg,
attr,
Expand Down Expand Up @@ -426,9 +417,7 @@ def __call__(self, inst, attr, value):
self.value_validator(inst, attr, value[key])

def __repr__(self):
return (
"<deep_mapping validator for objects mapping {key!r} to {value!r}>"
).format(key=self.key_validator, value=self.value_validator)
return f"<deep_mapping validator for objects mapping {self.key_validator!r} to {self.value_validator!r}>"


def deep_mapping(key_validator, value_validator, mapping_validator=None):
Expand Down Expand Up @@ -640,12 +629,7 @@ def __call__(self, inst, attr, value):
)

def __repr__(self):
return (
"<not_ validator wrapping {what!r}, capturing {exc_types!r}>"
).format(
what=self.validator,
exc_types=self.exc_types,
)
return f"<not_ validator wrapping {self.validator!r}, capturing {self.exc_types!r}>"


def not_(validator, *, msg=None, exc_types=(ValueError, TypeError)):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,14 @@ def test_repr(self, validator):

if isinstance(validator, list):
repr_s = (
"<optional validator for _AndValidator(_validators=[{func}, "
f"<optional validator for _AndValidator(_validators=[{always_pass!r}, "
"<instance_of validator for type <class 'int'>>]) or None>"
).format(func=repr(always_pass))
)
elif isinstance(validator, tuple):
repr_s = (
"<optional validator for _AndValidator(_validators=({func}, "
f"<optional validator for _AndValidator(_validators=({always_pass!r}, "
"<instance_of validator for type <class 'int'>>)) or None>"
).format(func=repr(always_pass))
)
else:
repr_s = (
"<optional validator for <instance_of validator for type "
Expand Down Expand Up @@ -1180,8 +1180,8 @@ def always_passes(inst, attr, value):

assert (
(
"not_ validator child '{!r}' did not raise a captured error"
).format(always_passes),
f"not_ validator child '{always_passes!r}' did not raise a captured error"
),
a,
always_passes,
input_value,
Expand Down Expand Up @@ -1276,8 +1276,8 @@ def test_composable_with_instance_of_fail(self):

assert (
(
"not_ validator child '{!r}' did not raise a captured error"
).format(instance_of((int, float))),
f"not_ validator child '{instance_of((int, float))!r}' did not raise a captured error"
),
a,
wrapped,
input_value,
Expand Down

0 comments on commit d129b1f

Please sign in to comment.