attrs/changelog.d
Libor Martínek 7c9b31ea7b
Add `attrs.validators.or_` validator (#1303)
* Implement attrs.validators.or_ validator

* Add tests/test_validators.py::TestOr test cases

* Add test for _OrValidator.__repr__ method

* Add description of attrs.validators.or_ to docs/api.rst

* Add changelog entry

* Swap double quotes for single because doctests don't like it

* Rename changelog fragment pointing to incorrect number

* Silence ruff linter warnings

Although good warning in general, in this particular code, they
do not fit here.

* BLE001 Do not catch blind exception: `Exception`
    `validators` usually raise `ValueError` upon their violation.
    However, it's not the only `Exception` they can raise - cf.
    `attrs.validators.not_` - therefore, it is desirable to catch
    them all!
* PERF203 `try`-`except` within a loop incurs performance overhead
    Fair point, but the loop is written in a way to short-circuit,
    ie. it will finish when a first validator is satisfied.
* S112 `try`-`except`-`continue` detected, consider logging the exception
    Not applicable here, we care only if **all** validators raise
    an exception, which is already accomodated for after the `for`
    loop.

* Apply suggestions from code review

Co-authored-by: Hynek Schlawack <hs@ox.cx>

* Rework example of or_ validator in api/docs.rst

* Update docs/api.rst

---------

Co-authored-by: Hynek Schlawack <hs@ox.cx>
Co-authored-by: Libor <libas.martinek@protonmail.com>
2024-07-17 12:01:41 +00:00
..
1221.change.md Update 1221.change.md 2024-01-07 08:13:27 +01:00
1234.change.md Tweak stubs for better VS Code import (#1234) 2024-02-04 06:00:30 +00:00
1253.change.md Preserve AttributeError in slotted classes with cached_property (#1253) 2024-04-02 04:57:25 +00:00
1263.deprecation.md Deprecate attr.s's repr_ns (#1263) 2024-03-16 15:55:37 +00:00
1264.breaking.md evolve: remove support for passing instances per kw (#1264) 2024-03-16 18:23:17 +00:00
1265.breaking.md Remove attrs.validators.provides (#1265) 2024-03-16 21:15:47 +00:00
1268.breaking.md Remove non-version metadata hack (#1268) 2024-03-18 15:19:38 +01:00
1285.change.md make_class(): Add "__annotations_" to generated class (#1285) 2024-07-13 10:52:46 +00:00
1303.change.md Add `attrs.validators.or_` validator (#1303) 2024-07-17 12:01:41 +00:00
towncrier_template.md.jinja Add missing empty lines to changelog btw releases 2024-05-27 20:11:05 +02:00