title: How to check if a variable is an instance of mpfr in Python 3?
body: <p>I want to know how to check whether a variable is of type mpfr or not, this might sound trivial but a simple <code>isinstance(v, mpfr)</code> can't do the trick.</p>
  <p>Example: create a variable that is an instance of mpfr, how to verify said variable is an instance of mpfr?</p>
  <pre class="lang-py prettyprint-override"><code>import gmpy2
  from gmpy2 import mpfr
  
  f = mpfr('0.5')
  </code></pre>
  <p>The most intuitive way fails:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; isinstance(TAU, mpfr)
  TypeError: isinstance() arg 2 must be a type or tuple of types
  </code></pre>
  <p>Because <code>mpfr</code> is a function:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; mpfr
  &lt;function gmpy2.mpfr&gt;
  </code></pre>
  <p><code>gmpy2</code> only has one attribute named <code>mpfr</code>, and it is the above function.</p>
  <p>However the class of the output of the <code>mpfr</code> function is also called <code>mpfr</code>:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; f.__class__
  mpfr
  </code></pre>
  <p>But this <code>mpfr</code> isn't the <code>mpfr</code> function in the main namespace:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; type(f) == mpfr
  False
  </code></pre>
  <p>So far I have only managed to check whether or not a variable is an instance of <code>mpfr</code> by creating an empty <code>mpfr</code> instance and use its <code>__class__</code> attribute:</p>
  <pre class="lang-py prettyprint-override"><code>isinstance(f, mpfr().__class__)
  </code></pre>
  <p>How can I access <code>&lt;class 'mpfr'&gt;</code> directly?</p>