Yury Selivanov wrote: > Christoph Groth <christ...@grothesque.org> wrote: > > Did you consider anything like that? For example, ContextVar could > > accept an optional keyword arg 'validate' that must be a function > > that is then called for each new value, and somehow reports problems > > (by return value or by raising an exception). > > For that you should definitely use a wrapper. Let's use composition > instead of complicating the existing APIs.
Agree in principle, but how would that work? If it was possible to derive a Python class from ContextVar, one could add the checking easily and transparently. But unfortunately that's not possible (perhaps it could be fixed?). The other possibility I see would be wrapping ContextVar inside a class (like in the example module that I attached to the first post in this thread), but that's not a good solution. It requires replicating the complete API, and is hence slow and not forward-compatible.
signature.asc
Description: PGP signature
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/3F2I4SA5HAOZFKFABCEETTWOAPUF4JJF/ Code of Conduct: http://python.org/psf/codeofconduct/