<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 09/06/2017 02:13 PM, Ronald Oussoren
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:ACAFE1EF-C8B4-4AFA-8616-AA4039039D6B@mac.com">
      <div>To be honest this sounds like a fairly crude hack. Updating
        the __class__ of a module object feels dirty, but at least you
        get normal behavior w.r.t. properties.</div>
    </blockquote>
    <br>
    Okay.  Obviously I disagree, I think it's reasonable.  But I'll
    assume you're -1.<br>
    <br>
    <br>
    <blockquote type="cite"
      cite="mid:ACAFE1EF-C8B4-4AFA-8616-AA4039039D6B@mac.com">
      <div>Why is there no mechanism to add new descriptors that can
        work in this context?</div>
    </blockquote>
    <br>
    I've updated the prototype to add one.  I added it as
    "collections.abc.InstanceDescriptor"; that's a base class you can
    inherit from, and then your descriptor will work in a module. 
    Bikeshedding the name is fine.<br>
    <br>
    <br>
    <blockquote type="cite"
      cite="mid:ACAFE1EF-C8B4-4AFA-8616-AA4039039D6B@mac.com">
      <div>BTW. The interaction with import is interesting… Module
        properties only work as naive users expect when accessing them
        as attributes of the module object, in particular importing the
        name using “from module import prop” would only call the
        property getter once and that may not be the intended behavior.</div>
    </blockquote>
    <br>
    I spent a fair amount of time thinking about this.  The short answer
    is: we <i>could</i> fix it.  We <i>could</i> make it so that "from
    x import y", when x.y is an instance descriptor, ensures that y
    honors the descriptor protocol when referenced.  We'd have to do it
    for three contexts:<br>
    <ul>
      <li>global scope (aka module scope)</li>
      <li>class scope</li>
      <li>function scope</li>
    </ul>
    The first two are pretty similar; create a proxy object that retains
    the module instance so it remains "bound" to that.  The third one is
    trickier; it'd mean a new bytecode (LOAD_FAST_DESCRIPTOR), but it
    wouldn't slow down people who didn't use it.<br>
    <br>
    Anyway, long story short, I think this would be worse than simply
    having "from x import y" only calling the getter once.  As the Zen
    says: special cases aren't special enough to break the rules.<br>
    <br>
    <br>
    <i>/arry</i><br>
  </body>
</html>