Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73753

Re: Creating a dict-like class that counts successful and failed key matches

Date 2014-06-30 10:09 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Creating a dict-like class that counts successful and failed key matches
References <1404135829.10485.136092537.2F0486D2@webmail.messagingengine.com> <CAPTjJmpkz4DPyCYSPNoteUuuBOzySzhjHzYPEXUv4MFH1sYE1A@mail.gmail.com> <1404139465.27658.136120269.0CA38211@webmail.messagingengine.com> <53B18398.4090302@stoneleaf.us> <1404146834.28955.136173757.51576D44@webmail.messagingengine.com>
Newsgroups comp.lang.python
Message-ID <mailman.11348.1404148248.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 06/30/2014 09:47 AM, python@bdurham.com wrote:
>>
>> Keep in mind that dict /will not/ call your overridden methods, so if,
>> for example, you provide your own __getitem__ you will also need to
>> provide your own copies of any dict method that calls __getitem__.
>
> I'm not sure I understand. Are you saying that Chris's __getitem__ will
> not be called by other dict methods that would normally call this magic
> method and instead call the parent's __getitem__ directly (via super()
> or something similar?)?

That is what I am saying.


> Is this specific to the native Dict class (because its implemented in C
> vs. Python?) or is this behavior more general.

I /think/ it's only dict, but I haven't played with subclassing lists, tuples, etc.  It's not a C vs Python issue, but a 
'implemented with __private methods' issue.  From what I have seen so far in the confusion and frustration that decision 
has caused, I do not think it was a good one.  :(

--
~Ethan~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Creating a dict-like class that counts successful and failed key matches Ethan Furman <ethan@stoneleaf.us> - 2014-06-30 10:09 -0700

csiph-web