>> This is a new PEP to implement Execution Contexts in Python.

> The idea is of course great!

Thanks!

> A couple of issues for decimal:
>
>> Moreover, passing the context explicitly does not work at all for
>> libraries like ``decimal`` or ``numpy``, which use operator overloading.
>
> Instead of "with localcontext() ...", each coroutine can create a new
> Context() and use its methods, without any loss of functionality.
>
> All one loses is the inline operator syntax sugar.
>
> I'm aware you know all this, but the entire decimal paragraph sounds a bit
> as if this option did not exist.

The problem is that almost everybody does use the Decimal type
directly, as overloaded operators make it so convenient. It's not
apparent that using the decimal this way has a dangerous flaw.

>
>> Fast C API for packages like ``decimal`` and ``numpy``.
>
> _decimal relies on caching the most recently used thread-local context,
> which gives a speedup of about 25% for inline operators:
>
> https://github.com/python/cpython/blob/master/Modules/_decimal/_decimal.c#L1639

I've seen that, it's a clever trick!  With the current PEP 550
semantics it's possible to replicate this trick, you just store a
reference to the latest EC in your decimal context for cache
invalidation. Because ECs are immutable, it's a safe thing to do.

Yury
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to