[Python-3000] unit test for advanced formatting

Pete Shinners shredwheat at gmail.com
Wed Feb 28 06:50:16 CET 2007

I've gone over PEP3101 to create an initial unittest for the advanced
formatting. Based on this intro to the formatting syntax, I thought I'd also
share my thoughts. I've also experimented with this against the python
prototype of the formatting.

I have commented out the tests where that implementation fails, but should
work (by my interpretation). If anything these tests will provide a preview
look at the way the formatting looks.

1. The early python implementation does not allow "reusing" an argument
either by index or by keyword name. The PEP has not defined this behavior. I
think it is important to be allowed to reuse any of the argument objects
given to format.

2. The implementation we have always requires a "fill" argument in the
format, if a width is specified. It would be a big improvement if space
characters were default.

3. The specification is deep. It will take an intense amount of unit testing
of corner cases to make sure this is actually doing what is correct. It may
be too complex, but it is hard to know what might be yagni.

4. The PEP still leaves a bit of wiggle room in the design, but since an
implementation is underway, I think more experimentation would be better
before locking down the design.

5. The "strict mode" activation through a global state on the string object
is a bad idea. I would prefer some sort of "flags" argument passed to each
function. I would prefer the "strict" mode where exceptions are raised by
default. But I do not want the strict behavior of requiring all arguments to
be used.

6. Security on the attribute lookups is probably an unending topic. A simple
minimum would be to not allow attribute lookups on names starting with an
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070227/47ef8085/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_format.py
Type: text/x-python
Size: 5990 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20070227/47ef8085/attachment-0001.py 

More information about the Python-3000 mailing list