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

2014-06-30 Thread python
As a diagnostic tool, I would like to create a dict-like class that counts successful and failed key matches by key. By failed I mean in the sense that a default value was returned vs. an exception raised. By count, I mean by tracking counts for individual keys vs. just total success/failure

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

2014-06-30 Thread python
After some additional research, it looks like I may have even more options to consider including using a UserDict mixin. I think I've identified another magic method to subclass ... __missing__. - Original message - From: [1]pyt...@bdurham.com To: [2]python-list@python.org

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

2014-06-30 Thread Chris Angelico
On Mon, Jun 30, 2014 at 11:43 PM, pyt...@bdurham.com wrote: As a diagnostic tool, I would like to create a dict-like class that counts successful and failed key matches by key. By failed I mean in the sense that a default value was returned vs. an exception raised. By count, I mean by

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

2014-06-30 Thread python
Hi Chris, Sounds like you want to subclass dict, then. Something like this: Nice!!! I need to study your solution, but at first blush it looks exactly like what I wanted to implement. Thank you! Malcolm -- https://mail.python.org/mailman/listinfo/python-list

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

2014-06-30 Thread Ethan Furman
On 06/30/2014 07:44 AM, pyt...@bdurham.com wrote: Nice!!! I need to study your solution, but at first blush it looks exactly like what I wanted to implement. Keep in mind that dict /will not/ call your overridden methods, so if, for example, you provide your own __getitem__ you will also

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

2014-06-30 Thread python
Ethan, 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

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

2014-06-30 Thread Ethan Furman
On 06/30/2014 09:47 AM, pyt...@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

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

2014-06-30 Thread python
Ethan, 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'

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

2014-06-30 Thread Chris Angelico
On Tue, Jul 1, 2014 at 2:47 AM, pyt...@bdurham.com wrote: 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