i&#39;ve had some difficulty with code that attempts to locate a type<br>by its __module__ and __name__, something like:<br>&nbsp;&nbsp;&nbsp; getattr(sys.modules[t.__module__], t.__name__)<br><br>the trouble is, all builtin types claim to belong to the __builtin__ module. 
<br>for example:<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; types.FunctionType<br>&nbsp;&nbsp;&nbsp; &lt;type &#39;function&#39;&gt;<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; types.FunctionType.__name__<br>&nbsp;&nbsp;&nbsp; &#39;funcrtion&#39;<br>
&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; types.FunctionType.__module__<br>&nbsp;&nbsp;&nbsp; &#39;__builtin__&#39;<br><br>but --<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; __builtin__.function<br>&nbsp;&nbsp;&nbsp; Traceback (most recent call last):<br>&nbsp; &nbsp; &nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
<br>&nbsp;&nbsp;&nbsp; AttributeError: &#39;module&#39; object has no attribute &#39;function&#39;<br><br>most, but not all, of the types are exposed in __builtin__... this required<br>me to create an artificial mapping in which &quot;__builtin__.function&quot; is mapped 
<br>to types.FunctionType, and then use this mapping instead of sys.modules,<br>which adds more special cases on my part.<br><br>on the other hand, the exceptions module works differently. all builtin<br>exceptions are defined in the exceptions module, but are exposed 
<br>through __builtin__:<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; EOFError.__module__<br>&nbsp;&nbsp;&nbsp; &#39;exceptions&#39;<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; exceptions.EOFError<br>&nbsp;&nbsp;&nbsp; &lt;type &#39;exceptions.EOFError&#39;&gt;<br>&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; __builtin__.EOFError
<br>
&nbsp;&nbsp;&nbsp; &lt;type &#39;exceptions.EOFError&#39;&gt;<br>
<br>so i thought why not do the same with all builtin types? currently the<br>types module (types.py) exposes some type objects (not all), and uses<br>witchcraft to obtain them:<br>&nbsp;&nbsp;&nbsp; try:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise TypeError<br>
&nbsp;&nbsp;&nbsp; except TypeError:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tb = sys.exc_info()[2]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TracebackType = type(tb)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FrameType = type(tb.tb_frame)<br><br>instead, let&#39;s make it a builtin module, in which all types will be defined;<br>
the useful types (int, str, ...) would be exposed into __builtin__ (just as <br>the exceptions module does), while the less useful will be kept unexposed.<br><br>this would make FunctionType.__module__ == &quot;types&quot;, rather than &quot;__builtin__&quot;,
<br>which would allow me to fetch it by name from sys.modules.<br><br><br>-tomer<br>