Python override __getattr__ for nested assignment, but not for referencing?
<p>Here's the behavior I'm looking for:</p>

<pre><code>&gt;&gt;&gt; o = SomeClass()
&gt;&gt;&gt; # Works: 
&gt;&gt;&gt; o.foo.bar = 'bar' 
&gt;&gt;&gt; print o.foo.bar
'bar'
&gt;&gt;&gt; # The in-between object would be of type SomeClass as well:
&gt;&gt;&gt; print o.foo 
&gt;&gt;&gt; &lt;__main__.SomeClass object at 0x7fea2f0ef810&gt;

&gt;&gt;&gt; # I want referencing an unassigned attribute to fail: 
&gt;&gt;&gt; print o.baz
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 5, in &lt;module&gt;
    print o.baz
AttributeError: 'SomeClass' object has no attribute 'baz'
</code></pre>

<p>In other words, I want to override <code>__getattr__</code> and <code>__setattr__</code> (and possibly <code>__getattribute__</code>) in such a way that work similarly to defaultdict, allowing assignment to arbitrary attributes, but if an attribute is just referenced but not assigned to, that it throws an AttributeError as it normally would. </p>

<p>Is this possible?</p>
