class_docstr: Rational number implementation that is intended to be compatible with
  gmpy2's mpq.
  
  Also slightly faster than fractions.Fraction.
  
  PythonMPQ should be treated as immutable although no effort is made to
  prevent mutation (since that might slow down calculations).
class_docstr_tok: ["Rational","number","implementation","that","is","intended","to","be","compatible","with","gmpy2","'s","mpq",".","Also","slightly","faster","than","fractions.Fraction",".","PythonMPQ","should","be","treated","as","immutable","although","no","effort","is","made","to","prevent","mutation","(","since","that","might","slow","down","calculations",")","."]
docstr: Construct PythonMPQ with gcd computation and checks
docstr_tok: ["Construct","PythonMPQ","with","gcd","computation","and","checks"]
code: def __new__(cls, numerator, denominator=None):
      """Construct PythonMPQ with gcd computation and checks"""
      if denominator is not None:
          #
          # PythonMPQ(n, d): require n and d to be int and d != 0
          #
          if isinstance(numerator, int) and isinstance(
              denominator, int
          ):
              # This is the slow part:
              divisor = gcd(numerator, denominator)
              numerator //= divisor
              denominator //= divisor
              return cls._new_check(numerator, denominator)
      else:
          #
          # PythonMPQ(q)
          #
          # Here q can be PythonMPQ, int, Decimal, float, Fraction or str
          #
          if isinstance(numerator, int):
              return cls._new(numerator, 1)
          elif isinstance(numerator, PythonMPQ):
              return cls._new(
                  numerator.numerator, numerator.denominator
              )
  
          # Let Fraction handle Decimal/float conversion and str parsing
          if isinstance(numerator, (Decimal, float, str)):
              numerator = Fraction(numerator)
          if isinstance(numerator, Fraction):
              return cls._new(
                  numerator.numerator, numerator.denominator
              )
      #
      # Reject everything else. This is more strict than mpq which allows
      # things like mpq(Fraction, Fraction) or mpq(Decimal, any). The mpq
      # behaviour is somewhat inconsistent so we choose to accept only a
      # more strict subset of what mpq allows.
      #
      raise TypeError("PythonMPQ() requires numeric or string argument")
  
imports: import operator
  from math import gcd
  from decimal import Decimal
  from fractions import Fraction
  import sys
  from typing import Tuple, Type
label_desc: Use image node_id 1 for calling the PythonMPQ obj's underlying member method code with example usage: obj.__new__(cls, numerator, denominator) and returns: cls, cls, cls, cls