Understanding Python through its builtins
This is a neat article, but it does have some errors.<p>One subtle point that the post gets wrong:<p>&gt; So where does that come from? The answer is that Python stores everything inside dictionaries associated with each local scope. Which means that every piece of code has its own defined “local scope” which is accessed using locals() inside that code, that contains the values corresponding to each variable name.<p>The dictionary returned by `locals()` is not literally a function&#x27;s local namespace, it&#x27;s a <i>copy</i> of that namespace. The actual local namespace is an array that is part of the frame object; in this way, references to local variables may happen much more quickly than would be the case if it had to look each variable up in a dictionary every time.<p>One consequence of this is that you can&#x27;t mutate the dict returned by `locals()` in order to change the value of a function-local variable.<p>Another, less-subtle error in the post is this:<p>&gt; int is another widely-used, fundamental primitive data type. It’s also the lowest common denominator of 2 other data types: , float and complex. complex is a supertype of float, which, in turn, is a supertype of int.<p>&gt; What this means is that all ints are valid as a float as well as a complex, but not the other way around. Similarly, all floats are also valid as a complex.<p>Oh, no no no. Python integers are arbitrary-precision integers. Floats are IEEE 754 double-precision binary floating-point values, and as such only support full integer precision up to 2^53. The int type can represent values beyond that range which the float type cannot.<p>And while it is true that the complex type is just two floats stuck together, I would very much not call it a <i>supertype</i>. It performs distinct operations.<p>&gt; Accessing an attribute with obj.x calls the __getattr__ method underneath. Similarly setting a new attribute and deleting an attribute calls __setattr__ and __detattr__ respectively.<p>Attribute lookup in Python is <i>way</i> more complex than this. It&#x27;s an enormous tar pit, too much so to detail in this comment, but __getattr__ is most often not involved, and the `object` type doesn&#x27;t even <i>have</i> a __getattr__ method.