You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Making it internal would mean _CountingAttr.__init__ and .validator could call .reify (or whatever) to get the real instance, thus allowing the machinery for expression building to be released.
Supporting VAL.user_method(...) or even VAL(...), means the __call__ method must inspect its arguments to determine if it's still being used to construct an expression or if it's actually validating. The scenario where someone is passing an Attribute as the second of three arguments is unlikely, but it is a validator so bizarre inputs are to be expected. (Other schemes like inspecting the call stack or assuming that the first validation means it's never going to be used to construct expressions are either cpython specific or could lead to heisenbugs.)
Of course, there's no point doing that for an external package as the versions will never match, so it may as well just inspect its arguments.
Putting/trying to put it into attrs straightaway would complicate things for you and impede its development.
Here's a quick mockup of the idea.
The idea is to provide a special token VAL that constructs validators using magic methods so you can write:
And, of course, it can report the expression in the exception it raises.
Things to support in a real version:
__getitem__
to check keys__getattr__
to allow property and method checksin
and such__call__
validates in the mockup, butattr.ib
should tell the object to convert itself to a validatorI'd like to see what the community thinks before putting together a proper PR.
The text was updated successfully, but these errors were encountered: