Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Python 2.6, a class decorator that's also a custom descriptor matches the specs you give:</p> <pre><code>class InnerClassDescriptor(object): def __init__(self, cls): self.cls = cls def __get__(self, instance, outerclass): class Wrapper(self.cls): outer = instance Wrapper.__name__ = self.cls.__name__ return Wrapper class Outer(object): @InnerClassDescriptor class Inner(object): def __init__(self): print self.outer o = Outer() i = o.Inner() print 'Outer is a', type(Outer) print 'Inner is a', type(o.Inner) </code></pre> <p>This emits:</p> <pre><code>&lt;__main__.Outer object at 0x82f90&gt; Outer is a &lt;type 'type'&gt; Inner is a &lt;type 'type'&gt; </code></pre> <p>just to confirm that </p> <blockquote> <p>o.Inner [[is]] a class object, not something weird like a closure</p> </blockquote> <p>as per your peculiar specs. Of course it needs to be a <em>different</em> class each time for reentrancy -- even in a single-threaded world, the following:</p> <pre><code>o1 = Outer() o2 = Outer() i1 = o1.Inner i2 = o2.Inner print i1(), i2(), i1(), i2() </code></pre> <p>should work cleanly, and stashing o1 vs o2 anywhere else than in the classes returned by <code>o1.Inner</code> vs <code>o2.Inner</code> (e.g., in TLS) would mean horrible results for this use.</p> <p>But then you <em>didn't</em> specify "<code>o.Inner</code> has to be <strong>exactly</strong> the same class object for <em>every</em> possible <code>o</code> that's an instance of <code>Outer</code>", so this code fully meets the specs you <em>did</em> give;-).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload