[issue1780] Decimal constructor accepts newline terminated strings

2008-01-11 Thread Mark Dickinson
Mark Dickinson added the comment: Committed, revision 59929. -- status: open -> closed __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list ma

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Please apply the patch and close the bug. Thx -- resolution: -> accepted __ Tracker <[EMAIL PROTECTED]> __ __

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-11 Thread Mark Dickinson
Mark Dickinson added the comment: Here's a patch that alters the Decimal constructor to allow leading and trailing whitespace. The Context.create_decimal method should now be a fully conforming implementation of to-number: it doesn't accept any leading or trailing whitespace. -- key

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-11 Thread Guido van Rossum
Guido van Rossum added the comment: > Do you want to be able to do Decimal("3 ") but not Decimal("3\n")? I want either both or none, with a slight preference for both but only if it can be done without breaking the spec. The status quo is that "3 " is refused but "3\n" is accepted; that seems w

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-11 Thread Facundo Batista
Facundo Batista added the comment: Mark Dickinson: > The other option that maintains full compliance with the > specification is to do what we like with Decimal.__new__ > (e.g. allowing leading and trailing whitespace), but > make sure that there's a fully conforming to-number > elsewhere in

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-10 Thread Guido van Rossum
Guido van Rossum added the comment: I'd say that accepting a trailing \n is a bug that should be fixed. I think that ideally we'd be allowed to specify whitespace around the value. I am always annoyed at programs that require me to type e.g. an integer and don't let me put spaces before and/or a

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-10 Thread Mark Dickinson
Mark Dickinson added the comment: I can certainly fix the Decimal constructor to reject trailing newlines, if that's what people want, but that doesn't fit with the proposal to accept and strip leading and trailing whitespace. The other option that maintains full compliance with the specificat

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-10 Thread Guido van Rossum
Guido van Rossum added the comment: > Allowing leading and trailing whitespace causes failures in Cowlishaw's > test suite. I guess Raymond's right: this bug report should be > dismissed. It still bothers me a little that there isn't a strictly > conforming implementation of to-number in decim

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-10 Thread Mark Dickinson
Mark Dickinson added the comment: Allowing leading and trailing whitespace causes failures in Cowlishaw's test suite. I guess Raymond's right: this bug report should be dismissed. It still bothers me a little that there isn't a strictly conforming implementation of to-number in decimal, but

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-10 Thread Facundo Batista
Facundo Batista added the comment: I think that the Spec disallows additional whitespace to not allow, for example, "2. 34" as "2.34", or "10 e-12". I don't see any harm in having " 2.34" or "5.73\n" as good input values, as long we remove those characters at both ends. I propose to just make

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: I think the decimal exceptions should continue to be raised as-is. There is a well-defined and thought-out structure for the Decimal exceptions. Also, the constructor's exceptions tend to be raised in an environment where there are other decimal operations t

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Mark Dickinson
Mark Dickinson added the comment: In the spirit of making the Decimal constructor match the rest of the language, can I propose another change: make Decimal("not a decimal") raise a ValueError. Currently, Decimal("not a decimal") either raises InvalidOperation or returns a Decimal NaN, depen

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Mark Dickinson
Mark Dickinson added the comment: Aargh! It's only the Context class that needs a to_number method---it makes no sense as a Decimal method. And to_number is almost already there, in the form of Context.create_decimal. I'll work out exactly what the minimum is that needs to be done to comply

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Mark Dickinson
Mark Dickinson added the comment: Okay: in that case, I propose: (1) adding a to_number method to the Decimal and Context class, so that we're still in full compliance with the specification, and (2) altering Decimal.__new__ to allow trailing and leading whitespace. ___

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: I concur with Guido. The to-number operation is part of the spec. The constructor belongs to us and should match the rest of the language. -- nosy: +rhettinger __ Tracker <[EMAIL PROTECTED]>

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Guido van Rossum
Guido van Rossum added the comment: I'd propose doing the same thing as int() and float(), which accept and strip leading and trailing whitespace. -- nosy: +gvanrossum __ Tracker <[EMAIL PROTECTED]> _

[issue1780] Decimal constructor accepts newline terminated strings

2008-01-09 Thread Mark Dickinson
New submission from Mark Dickinson: After seeing issue #1761, I realized that there's a bug in the Decimal constructor: it accepts newline-terminated strings: >>> from decimal import * >>> s = "2.3\n" >>> Decimal(s) Decimal("2.3") I think this is, strictly speaking, a bug because: (1) The IB