code: def parse_compound_count(s):
      
      m = re.match(r'^\((.*)\)$', s)
      if m:
          s = m.group(1)
  
      for count_type in (int, Decimal, affine.Expression):
          try:
              return count_type(s)
          except:
              pass
  
      raise ValueError('Unable to parse compound count: {}'.format(s))
docs: Parse a compound count (number of compounds).