On Wed, 6 Apr 2022 at 09:59, Mark Dickinson via Python-ideas <python-ideas@python.org> wrote: > > Broken off from the "Custom literals, a la C++" thread: > > Greg Ewing wrote: > >Personally I think giving Decimal a global context was a mistake, [...] > > so arguing that "it's no worse than Decimal" isn't going to do much > > to convince me. :-) > > I'd be curious to know what alternatives you see. When a user writes `x + y` > with both `x` and `y` instances of `decimal.Decimal`, the decimal module > needs to know what precision to compute the result to (as well as what > rounding mode to use, etc.). Absent a thread-local context or task-local > context, where would that precision information come from?
One possibility is to attach the context information to the instances so it's like: ctx = context(precision=10, ...) x = ctx.new('1.2') y = ctx.new('2.3') z = x / y # rounds to 10 digits Of course there are many complications here when you think about mixing numbers that have different contexts so you'd need to decide how to handle that. One possibility would be simply to disallow mixing instances with different contexts and require explicit conversions. Realistically do many users want to use many different contexts and regularly switch between them? I expect the common use case is wanting to do everything in a particular context that just isn't the default one. -- Oscar _______________________________________________ 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/WREYX3W2XKCJADXDINOGDG5MLNP4YMSI/ Code of Conduct: http://python.org/psf/codeofconduct/