On Sat, Feb 20, 2016 at 11:24 AM, Ian Kelly wrote:
>> Look like inheriting from defaultdict is easier. I don't even have to
>> override the constructor as suggested by Chris Angelico above. Thanks.
>
> True, although there's a faint code smell as this technically violates
> the Liskov Substitutio
On Thu, Feb 18, 2016 at 10:41 AM, Herman wrote:
> From: Ben Finney
>>
>> you are using the inheritance hierarchy but thwarting it by not using
>> ‘super’. Instead::
>>
>> super().__init__(self, default_factory, *a, **kw)
>>
>> and::
>>
>> super().__getitem__(self, key)
>> --
>> \ "
d = dictutil.DefaultDictWithEnhancedFactory(lambda k: k)
self.assertEqual("apple", d['apple'])
From: Ben Finney
>
> you are using the inheritance hierarchy but thwarting it by not using
> ‘super’. Instead::
>
> super().__init__(self, default_factory, *a, **kw)
>
> and::
>
> super(
Herman wrote:
I want to pass in the key to the default_factory of defaultdict and I found
that defaultdict somehow can intercept my call to dict.__getitem__(self,
key),
What's happening here is that defaultdict doesn't actually
override __getitem__ at all. Instead, it overrides __missing__,
whi
On Monday 15 February 2016 11:17, Herman wrote:
> I want to pass in the key to the default_factory of defaultdict
Just use a regular dict and define __missing__:
class MyDefaultDict(dict):
def __missing__(self, key):
return "We gotcha key %r right here!" % key
If you want a per-in
On Mon, Feb 15, 2016 at 11:17 AM, Herman wrote:
> I want to pass in the key to the default_factory of defaultdict and I found
> that defaultdict somehow can intercept my call to dict.__getitem__(self,
> key), so my class's __getitem__ have to catch a TypeError instead instead
> of KeyError. The fo
Herman writes:
> I want to pass in the key to the default_factory of defaultdict and I
> found that defaultdict somehow can intercept my call to
> dict.__getitem__(self, key), so my class's __getitem__ have to catch a
> TypeError instead instead of KeyError. The following class is my code:
I don
I want to pass in the key to the default_factory of defaultdict and I found
that defaultdict somehow can intercept my call to dict.__getitem__(self,
key), so my class's __getitem__ have to catch a TypeError instead instead
of KeyError. The following class is my code:
class DefaultDictWithEnhancedF