On 09/07/2017 03:37 AM, Greg Ewing wrote: > If I understand correctly, instead of using a context > manager, your fractions example could be written like > this: > > def fractions(precision, x, y): > ctx = decimal.getcontext().copy() > decimal.setcontext(ctx) > ctx.prec = precision > yield MyDecimal(x) / MyDecimal(y) > yield MyDecimal(x) / MyDecimal(y ** 2) > > and it would work without leaking changes to the decimal > context, despite the fact that it doesn't use a context > manager or do anything else to explicitly put back the > old context. The disagreement seems to be whether a LogicalContext should be created implicitly vs explicitly (or opt-out vs opt-in). As a user trying to track down a decimal context change not propagating, I would not suspect the above code of automatically creating a LogicalContext and isolating the change, whereas Greg's context manager version is abundantly clear. The implicit vs explicit argument comes down, I think, to resource management: some resources in Python are automatically managed (memory), and some are not (files) -- which type should LCs be? -- ~Ethan~
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4