A classmate asked a question about overwriting the built-in class dict, and after some poking around I became even more uncertain.
Take the built-in dict. I can assign this variable:
>>> dict=5
>>> dict
5
Now I've lost access to dict (would this be shadowing like in C++ or is it different?) but I still have access to the class via builtins.dict. But I can overwrite that as well:
>>> __builtins__.dict = 6
>>> __builtins__.dict
6
But even doing this doesn't break the class itself:
>>> stillDict = {'key': 'value'}
>>> stillDict
{'key': 'value'}
So why does the class still "work" after I've shadowed it? How does the interpreter know I'm making a dictionary with this assignment, and how is the dictionary constructed since it obviously doesn't actually require __builtins__.dict?
edit Taking this a bit further, from simeon's answer which says it's because I'm creating a dictionary literal ...
before overwriting, I can do this:
>>> a = dict()
>>> a.items
<built-in method items of dict object at 0x0000000002C97C08>
after overwriting dict and __builtins__.dict, I can do this:
>>> b = {}
>>> b.items
<built-in method items of dict object at 0x000000000288FC88>
Which leads to a follow-on ... Both of these are still "dict objects", is the dict class just using a constructor to make a dict object? Why do I still have access to the built-in methods once I've shadowed the class?