Check if variable is a standard type function in Python
<p>I'm looking for a way to catch all the std type functions in Python (int, str, xrange, etc).</p>

<p>Basically anything which has a repr that looks like <code>&lt;type X&gt;</code> instead of <code>&lt;class X&gt;</code>. Here's a full list of all std types in Python 2:
<a href="https://docs.python.org/2/library/stdtypes.html" rel="nofollow">https://docs.python.org/2/library/stdtypes.html</a></p>

<p>If I use <code>isinstance(X, type)</code> or <code>type(X) == type</code>, it also catches all classes too, but I only want to detect type functions (or any names that's assigned to one of them (i.e. <code>my_int = int</code>).</p>

<p>The only idea that comes to my mind is checking if <code>X.__name__</code> is in <code>__builtins__</code> but I'm not sure if that's a clean nor correct solution.</p>

<p>What you suggested seems good to me.</p>

<pre><code>builtin = dir(__builtins__)
def is_builtin(tested_object):
    return tested_object.__class__.__name__ in builtin
</code></pre>

<p>Bear in mind, however, that built-in types can be overshadowed.</p>

<p>Update after comment from Rob:</p>

<pre><code>def is_builtin(tested_object):
    return tested_object.__class__.__module__ == '__builtin__'
</code></pre>

python