<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/11/2017 07:22 PM, Guido van
      Rossum wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAP7+vJLBUFBNF9yLtk7oN2EM1Qe5t69_VxvxdTjqjvRewnf8+w@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>I still don't follow. How does one use
              InstanceDescriptor?</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    If you write a class that inherits from InstanceDescriptor and
    supports the descriptor protocol, module objects will call the
    descriptor protocol functions when that object is accessed inside a
    module instance.<br>
    <br>
    Example: if this is "module.py":<br>
    <blockquote>import collections.abc<br>
      class CustomInstanceProperty(collections.abc.InstanceDescriptor):<br>
          def __get__(self, instance, owner):<br>
              print("CustomInstanceProperty.__get__ called!")<br>
              return 44<br>
      <br>
      cip = CustomInstanceProperty()<br>
    </blockquote>
    <br>
    If you then "import module" and reference "module.cip", it'll print
    "CustomInstanceProperty.__get__ called!" and you'll get the value
    44.  All three magic methods for descriptors work fine.<br>
    <br>
    (BTW, I didn't know the best way to make this work.  I wound up
    implementing InstanceDescriptor by copying-and-pasting
    PyBaseObject_Type, setting the special tp_flag, and ensuring the
    special flag gets propagated to subclasses in inherit_special().  If
    there's a better way to do it I'd happily improve the
    implementation.)<br>
    <br>
    <br>
    <blockquote type="cite"
cite="mid:CAP7+vJLBUFBNF9yLtk7oN2EM1Qe5t69_VxvxdTjqjvRewnf8+w@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>Is this still about modules, or is it a generalization
              of properties for non-module instances? (If it is specific
              to modules, why doesn't it have "module" in its name? Or
              if it's not, why is it in this discussion?)<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    It's a generalization of supporting descriptors for instances, but
    currently it's only supported by modules.  It's opt-in and modules
    are the only class doing so.<br>
    <br>
    <br>
    <blockquote type="cite"
cite="mid:CAP7+vJLBUFBNF9yLtk7oN2EM1Qe5t69_VxvxdTjqjvRewnf8+w@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF"> The prototype is linked to from
                the PEP; for your convenience here's a link:<br>
                <blockquote><a
                    class="m_-5864820084921288750moz-txt-link-freetext"
href="https://github.com/larryhastings/cpython/tree/module-properties"
                    target="_blank">https://github.com/<wbr>larryhastings/cpython/tree/<wbr>module-properties</a><br>
                </blockquote>
              </div>
            </blockquote>
          </div>
          I found that link in the PEP, but it's just a branch of a fork
          of cpython. It would be easier to review the prototype as a PR
          to upstream cpython.<br>
        </div>
      </div>
    </blockquote>
    <br>
    Okay, I'll make a PR tomorrow and post a reply here (and update the
    PEP).<br>
    <br>
    <br>
    <i>/arry</i><br>
  </body>
</html>