diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5997be2..3ba83b17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/src/attr/validators.py b/src/attr/validators.py index 34d6b761..0cc8c118 100644 --- a/src/attr/validators.py +++ b/src/attr/validators.py @@ -97,12 +97,7 @@ class _InstanceOfValidator: 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, @@ -140,9 +135,7 @@ class _MatchesReValidator: 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, @@ -206,9 +199,7 @@ class _ProvidesValidator: 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, @@ -426,9 +417,7 @@ class _DeepMapping: self.value_validator(inst, attr, value[key]) def __repr__(self): - return ( - "" - ).format(key=self.key_validator, value=self.value_validator) + return f"" def deep_mapping(key_validator, value_validator, mapping_validator=None): @@ -640,12 +629,7 @@ class _NotValidator: ) def __repr__(self): - return ( - "" - ).format( - what=self.validator, - exc_types=self.exc_types, - ) + return f"" def not_(validator, *, msg=None, exc_types=(ValueError, TypeError)): diff --git a/tests/test_validators.py b/tests/test_validators.py index 4327f825..856da499 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -443,14 +443,14 @@ class TestOptional: if isinstance(validator, list): repr_s = ( - ">]) or None>" - ).format(func=repr(always_pass)) + ) elif isinstance(validator, tuple): repr_s = ( - ">)) or None>" - ).format(func=repr(always_pass)) + ) else: repr_s = ( "