pylint-bot / astroid-unofficial

UNOFFICIAL playground for astroid github migration
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Understand __missing__ #145

Open pylint-bot opened 9 years ago

pylint-bot commented 9 years ago

Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: PCManticore)


We could understand missing: when a key is not found in a dictionary, if it provides the dunder missing special method, then that method will be called and whatever is returned, will be the result of key access:

#!python

class A(dict):
   def __missing__(self, key): return 42

a = A()
print(a[10])