<div dir="ltr">Hi,<div><br><div class="gmail_extra"><div class="gmail_quote">2013/6/23 anatoly techtonik <span dir="ltr"><<a href="mailto:techtonik@gmail.com" target="_blank">techtonik@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div>Currently, the only way to get the name of the class that *defines* a method is to get chain of parent classes from inspect.getmro() and look into every class's dict until a given name is found. Knowing that dict contains not only methods, and knowing that it can be modified at run-time, this doesn't seem too reliable for me (unless Python itself does the same).<br>
</div></div></div></blockquote><div><br></div><div style>Python 3.3 has __qualname__, which may be very useful in your case:</div><div style><a href="http://docs.python.org/3/whatsnew/3.3.html#pep-3155-qualified-name-for-classes-and-functions">http://docs.python.org/3/whatsnew/3.3.html#pep-3155-qualified-name-for-classes-and-functions</a><br>
</div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>At first I wanted to propose an enhancement to runtime skeleton of Python, which is 2D lookup tree for objects and containers that define them. But then I realized that it will may not reflect the model I need. For example, classes need to provide their  parent classes, but in my model classes need to provide module name (or function name, or method name) in which they are defined.<br>


<br>And while writing this I realized that *definition* scope may be different from *run-time* scope, and Python doesn't make it clear:<br><br>>>> def lll():<br>...   class A(object):<br>...     pass<br>...   a=A()<br>


...   return a<br>... <br>>>> lll()<br><__main__.A object at 0x948252c><br>>>> __main__.A<br>Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>NameError: name '__main__' is not defined<br>


<br>The A object is said to be in __main__ namespace, but it seems to be a run-time namespace local to function and it seems like Python loses this information. There is no information about the function that defined the class (owner, parent or .?.), and hence no info about container of the function, which makes it hard to assume the scope of variables for this class at run-time.<br>


<br></div><br>So, the above is a generalization of a simple idea - store  the "structure reference" of the class that *defines* a method inside this method.  "structure reference" here is the address in the nested scopes formed by Python definitions.<br>


<div><br></div><div>The specific action items for you here are:<br></div><div>1. is that stuff will be useful (for me it brings some much needed consistency into the chaos of run-time Python object space)<br></div><div>2. what is the best way to define/cache the reference to the class defining the method?<br>


3.  what is the best way to define/cache the reference to the scope defining the method?<br>4.  what is the best way to organize storing of this static scope structure information at run-time?<br><br>See method.im_class note at<br>


<a href="http://docs.python.org/2/library/inspect.html#types-and-members" target="_blank">http://docs.python.org/2/library/inspect.html#types-and-members</a><br><div><br>"Namespaces are one honking great idea -- let's do more of those!" (c) import this<span class=""><font color="#888888"><br clear="all">


<div><div>-- <br>anatoly t.</div>
</div></font></span></div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Amaury Forgeot d'Arc
</div></div></div>