On Tue, Jan 16, 2018 at 2:44 PM, Yury Selivanov <yselivanov...@gmail.com> wrote: > 4. ContextVar.reset(token) now raises a ValueError if the token was > created in a different Context.
A minor bit of polish: given that Token objects have to track the associated ContextVar anyway, I think it'd be cleaner if instead of doing: token = cvar.set(...) cvar.reset(token) we made the API be: token = cvar.set(...) token.reset() In the first version, we use 'cvar' twice, and it's a mandatory invariant that the same ContextVar object gets used in both places; you had to add extra code to check this and raise an error if that's violated. It's level 5 on Rusty's scale (http://sweng.the-davies.net/Home/rustys-api-design-manifesto) In the second version, the ContextVar is only mentioned once, so the invariant is automatically enforced by the API -- you can't even express the broken version. That's level 10 on Rusty's scale, and gives a simpler implementation too. -n -- Nathaniel J. Smith -- https://vorpus.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com