Re: [Python-checkins] r61123 - in python/trunk: Lib/decimal.py Lib/test/test_decimal.py Misc/NEWS
Add __format__ method to Decimal, to support PEP 3101
Wow, the decimal module has grown to 5500 lines. Raymond
Raymond Hettinger <python <at> rcn.com> writes:
Wow, the decimal module has grown to 5500 lines.
Raymond
It would be really great if the code for parsing the format specifier and padding and aligning the formatted value could be put elsewhere in the std. lib.; it's really not decimal specific, and it could be potentially useful to other modules. Any suggestions for places to move it to? Mark
Mark Dickinson wrote:
Raymond Hettinger <python <at> rcn.com> writes:
Wow, the decimal module has grown to 5500 lines.
Raymond
It would be really great if the code for parsing the format specifier and padding and aligning the formatted value could be put elsewhere in the std. lib.; it's really not decimal specific, and it could be potentially useful to other modules.
Any suggestions for places to move it to?
As the parsing functions are specifically for numeric formatting support, the numbers module seems like a reasonable option to me. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
Nick Coghlan wrote:
Mark Dickinson wrote:
Raymond Hettinger <python <at> rcn.com> writes:
Wow, the decimal module has grown to 5500 lines.
Raymond
It would be really great if the code for parsing the format specifier and padding and aligning the formatted value could be put elsewhere in the std. lib.; it's really not decimal specific, and it could be potentially useful to other modules.
Any suggestions for places to move it to?
As the parsing functions are specifically for numeric formatting support, the numbers module seems like a reasonable option to me.
The int, long, and str formatters use the same parsing routine, then they each check that what they got was valid for their type. I went back and forth on this, but it ended up being less code if they shared the parsing routing. So, this doesn't apply exclusively to numbers, although I agree that will be the most common usage. Eric.
Mark Dickinson wrote:
Raymond Hettinger <python <at> rcn.com> writes:
Wow, the decimal module has grown to 5500 lines.
Raymond
It would be really great if the code for parsing the format specifier and padding and aligning the formatted value could be put elsewhere in the std. lib.; it's really not decimal specific, and it could be potentially useful to other modules.
Similarly, the C code to do the same thing could be made visible. Both of these could be used by non-builtin numeric types that want to implement __format__.
Any suggestions for places to move it to?
No particular suggestion, but if we create (for example) a formatlib, we could also create a _formatlib to hold the C implementations, and we would harmonize the interfaces. Although the fact that it's needed by the builtin types float and int make it tough to put it all in a loadable module.
participants (4)
-
Eric Smith
-
Mark Dickinson
-
Nick Coghlan
-
Raymond Hettinger