classification
Title: __missing__ does not get called
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, t-milich (2)
Priority: normal Keywords

Created on 2006-07-11 03:40 by t-milich, last changed 2006-07-11 07:01 by georg.brandl.

Messages (2)
msg29132 - (view) Author: Milind (t-milich) Date: 2006-07-11 03:40
On the last step a[10] we expect 100
>>> class A(dict):
...     pass
...
>>> a = A({1:2})
>>> def foo(a,b): return 100
...
>>> a.__missing__ = foo
>>> a[1]
2
>>> a.__missing__(10,20)
100
>>> a[10]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 10
msg29133 - (view) Author: Georg Brandl (georg.brandl) Date: 2006-07-11 07:01
Logged In: YES 
user_id=849994

Methods are looked up on the type, not the instance. Add
your __missing__ method to A to make it work.
History
Date User Action Args
2006-07-11 03:40:32t-milichcreate