This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2006-07-11 03:40 by t-milich, last changed 2022-04-11 14:56 by admin. This issue is now closed.

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) * (Python committer) 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
2022-04-11 14:56:18adminsetgithub: 43647
2006-07-11 03:40:32t-milichcreate