-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> * Rework example of or_ validator in api/docs.rst * Update docs/api.rst --------- Co-authored-by: Hynek Schlawack <[email protected]> Co-authored-by: Libor <[email protected]>
- Loading branch information
1 parent
37ac3ef
commit 7c9b31e
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added the `attrs.validators.or_()` validator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters