def __new__(cls, *_args, **kwargs):
    """Constructor.  See the class docstring for arguments."""
    if _args:
      if len(_args) == 1 and isinstance(_args[0], dict):
        if kwargs:
          raise TypeError('Key() takes no keyword arguments when a dict is the '
                          'the first and only non-keyword argument (for '
                          'unpickling).')
        kwargs = _args[0]
      else:
        if 'flat' in kwargs:
          raise TypeError('Key() with positional arguments '
                          'cannot accept flat as a keyword argument.')
        kwargs['flat'] = _args
    self = super(Key, cls).__new__(cls)
    # Either __reference or (__pairs, __app, __namespace) must be set.
    # Either one fully specifies a key; if both are set they must be
    # consistent with each other.
    if 'reference' in kwargs or 'serialized' in kwargs or 'urlsafe' in kwargs:
      (self.__reference,
       self.__pairs,
       self.__app,
       self.__namespace) = self._parse_from_ref(cls, **kwargs)
    elif 'pairs' in kwargs or 'flat' in kwargs:
      self.__reference = None
      (self.__pairs,
       self.__app,
       self.__namespace) = self._parse_from_args(**kwargs)
    else:
      raise TypeError('Key() cannot create a Key instance without arguments.')
    return self
dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/key.py/Key.__new__/original