There is a question about specifying the transform function.
There are three ways to do this:
1. Positional argument of the constructor.
d = TransformDict(str.casefold, Foo=5)
2. Subclassing.
class CaseInsensitiveDict(TransformDict):
def transform(self, key):
return key.casefold()
d = CaseInsensitiveDict(Foo=5)
3. Type generator.
d = TransformDict(str.casefold)(Foo=5)
Second method looks a little simpler to me from implementation side
(What if you call __init__ for already initialized object? What if you
used the object before calling __init__?).
Third method allows you to customize other aspects of dict behavior
(combine OrderedDict, defaultdict,..).
First method looks less cumbersome from user side at first look. But how
many different transform functions you use? Aren't they deserve named
classes?
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com