[Python-Dev] Catching "return" and "return expr" at compile time
Barry A. Warsaw
firstname.lastname@example.org (Barry A. Warsaw)
Tue, 7 Sep 1999 14:07:01 -0400 (EDT)
>>>>> "GW" == Greg Ward <email@example.com> writes:
GW> However, one could certainly envision a world where Python
GW> issues runtime warnings. If my time machine were working, I'd
GW> zip back and suggest to Guido that mistakes with the %
GW> operator should issue warnings rather than raising exceptions.
GW> (Ignore the language philosophy issue and presume this would
GW> be worthwhile.)
Moderately off-topic, but since you brought it up, here's what I use
in Mailman (since site-admins can make mistakes editing their
templates, which contains %(keys)s... we'd like to make Mailman more
robust so it doesn't totally crap out when that happens).
We (hopefully) always interpolate with a SafeDict instead of a raw
"""Dictionary which returns a default value for unknown keys.
This is used in maketext so that editing templates is a bit more robust.
def __init__(self, d):
# optional initial dictionary is a Python 1.5.2-ism. Do it this way
# for portability
def __getitem__(self, key):
if type(key) == StringType:
return '<Missing key: %s>' % `key`