[Python-Dev] Re: Alternative Implementation for PEP292:SimpleString Substitutions

Guido van Rossum gvanrossum at gmail.com
Wed Sep 8 17:08:07 CEST 2004


> Templates are meant to template *text* data, so Unicode is
> the right choice of baseclass from a design perspective.

Only in Python 3.0.

But even so, deriving from Unicode (or str) means the template class
inherits a lot of unwanted operations. While I can see that
concatenating templates probably works, slicing them or converting to
lowercase etc. make no sense. IMO the standard Template class should
implement a "narrow" interface, i.e. *only* the template expansion
method (__mod__ or something else), so it's clear that other
compatible template classes shouldn't have to implement anything
besides that. This avoids the issues we have with the mapping
protocol: when does an object implement enough of the mapping API to
be usable? That's currently ill-defined; sometimes, __getitem__ is all
you need, sometimes __contains__ is required, sometimes keys, rarely
setdefault.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
Ask me about gmail.


More information about the Python-Dev mailing list