Message50753
Logged In: YES
user_id=80475
The replacement of _multimap is a semantic change.
Formerly, a dictionary passed in as a positional argument is
left unmolested; now, it is mutated to reflect kwds. Also,
the _multimap setup is an O(1) step while the update()
approach is O(n). Also, the current implementation only
requires the positional argument to support __getitem__();
now, it requires a more fully compliant duck (one that
provides an .update() method).
- mapping = _multimap(kws, args[0])
+ mapping = args[0]
+ mapping.update(kws)
Current behavior:
>>> t = Template('the $speed brown')
>>> d = dict(speed='quick')
>>> t.safe_substitute(d, speed='slow')
'the slow brown'
>>> d
{'speed': 'quick'}
After the patch, it returns {'speed': 'slow'}.
Likewise the following now works, but would fail after the
patch:
>>> t = Template('the $speed brown')
>>> class D:
def __getitem__(self, key):
return 'quick'
>>> t.safe_substitute(D(), speed='slow')
'the slow brown'
The whole approach is misguided, and the use case itself is
suspect. If some change is warranted, consider a cleaner,
more general-purpose solution like having an optional key=
argument to the Template constructor for pre-processing keys:
>>> t = Template('the $speed brown', key=str.lower)
|
|
Date |
User |
Action |
Args |
2007-08-23 15:53:42 | admin | link | issue1528167 messages |
2007-08-23 15:53:42 | admin | create | |
|