-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
Make optional support lists of validators #186
Conversation
Codecov Report
@@ Coverage Diff @@
## master #186 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 9 9
Lines 554 560 +6
Branches 122 124 +2
=====================================
+ Hits 554 560 +6
Continue to review full report at Codecov.
|
So a small problem with this is that it makes the existing use case, with optional+just one subvalidator ~10% slower. I tried this approach:
This works (no overhead on one subvalidator) but this is ~10% slower for a list of subvalidators (and it doesn't have a nice repr). So why not just add an _OptionalValidators class in addition to the existing _OptionalValidator so we can have our cake and eat it too. Do we want to offer easy validator chaining as an API? Something like
With a little bit of black magic The syntax is clunky, but using |
Are you suggesting to make lists syntactic sugar for an |
Point 0: I see we already have an Point 1: It'd be possible to create a more efficient Point 2: We could expose the Point 3: Musings on syntax. Writing I don't think this is currently possible since the requirements for validators are that they are just ordinary functions. Using lists as a syntax for
So I want to validate I suggest we go with points 0 and 1 for this release and bikeshed the rest later. |
Point -1: 17.1 has to come out before PyCon. Realistically that means Saturday morning in my FOSS session.
Yes, I’m tending to use sqlalchemy vocabulary where possible.
Yeah, while a neato syntactic sugar, let's not get carried away.
No we can’t, but we can make the most common case nicer.
Yeah, let’s get 0 and 2 (just moving and exposing…) merged and do 1 in a separate PR. |
👍 |
Assuming tests will pass (Travis is quite drowsy today), how does this look? |
Will take a look in the evening. |
Serious question: can we live with an import at the end of a file? This will allow us to:
What this does is:
which is especially useful for |
I don’t quite follow, how would |
I meant something like
It's not a big deal, but it'd also let us make _AndValidator frozen and remove the |
Sorry if I'm not being clear, I'm a little tired. I'm saying
the equivalent is
I asked for the import because it'd be useful to have access to this |
I refuse to have circular imports but other than that, I believe I’ve realized your vision? N.B. attrs will never have any actually frozen classes. If people want to do that to their own stuff: go for it. But attrs itself won't run with an engaged handbrake Unless you find a ways to make it just as fast one day. ;) |
That's the plan ;) Anyway, I think this is good to go. Great work 💖 |
Fixes #161
Pull Request Check List
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!
.rst
files is written using semantic newlines.versionadded
,versionchanged
, ordeprecated
directives.CHANGELOG.rst
.