RE: [Python-Dev] Re: Decimal data type issues
[Tim Peters] #- The second way of spelling it is fine, but there's no need #- to cater to an #- optional context argument. Decimal.using_context(input) #- should use the #- current context object. It's been a general rule so far #- that all operations #- are available as methods *of* context objects too, so in the #- goofy case (I #- say "goofy" because I predict it won't be used in real life) #- of wanting to #- force use of a particular non-current context object c, the #- natural spelling #- is (or should be) #- #- c.using_context(input) You mean adding a method to the context, to create a Decimal using itself as context and not the one from the thread? If yes, what about c.create_decimal(number) ? And with floats? c.create_decimal_from_float(number)? Or the same method that before? . Facundo
On Thu, Apr 22, 2004, Batista, Facundo wrote:
If yes, what about c.create_decimal(number) ?
Sounds good. If you're going this route, it seems to me that Decimal() would work better if it ends up being a proxy class for an internal implementation that's more closely linked to context, and that most of the Decimal methods simply delegate to the internal implementation through context. (If you look at my original implementation, that's similar to the direction I was going -- haven't actually looked at your code to see what it's like currently.) Make sure that Decimal has-a internal implementation rather than is-a (i.e. use composition instead of subclassing).
And with floats? c.create_decimal_from_float(number)? Or the same method that before?
``from_float()`` probably is better. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "I used to have a .sig but I found it impossible to please everyone..." --SFJ
[Batista, Facundo]
You mean adding a method to the context, to create a Decimal using itself as context and not the one from the thread?
Yes. This isn't novel: all the operations are like that already. For example, Decimal.__abs__() is also available as Context.abs(decimal). The semantic difference is that the Decimal methods implicitly use the current thread's current context object, while the Context methods (trivially) use an explicitly specified context object.
If yes, what about c.create_decimal(number) ?
I think the name's kinda wordy. What else would a Decimal.Context object want to create, other than a Decimal.Decimal?
And with floats? c.create_decimal_from_float(number)? Or the same method that before?
I'd be happy with c.from_string(a_string) c.from_int(an_int_or_long) # and works identically to # c.from_string(str(an_int_or_long)) c.from_float(a_float) I have no intention of creating Decimals from floats, so I didn't pay attention to those arguments (other than to silently agree that the issues involved are ugly enough that float->Decimal should have its own spelling -- if we have to have it at all).
[Aahz]
Sounds good. If you're going this route, it seems to me that Decimal() would work better if it ends up being a proxy class for an internal implementation that's more closely linked to context, and that most of the Decimal methods simply delegate to the internal implementation through context.
The current implementation is approximately the opposite: most of the Decimal methods have an optional "context" argument, and most the Context methods delegate to Decimal methods (passing context=self). That's fine by me, and I don't see a compelling reason to turn it inside out at this stage. Both classes derive from (only) object.
participants (3)
-
Aahz
-
Batista, Facundo
-
Tim Peters