'Constructs a _QueryKeyFilter.
If app/namespace and ancestor are not defined, the app/namespace set in the
environment is used.
Args:
app: a string representing the required app id or None.
namespace: a string representing the required namespace or None.
kind: a string representing the required kind or None.
ancestor: a entity_pb.Reference representing the required ancestor or
None.
Raises:
datastore_erros.BadArgumentError if app and ancestor.app() do not match or
an unexpected type is passed in for any argument.'

@datastore_rpc._positional(1)
def __init__(self, app=None, namespace=None, kind=None, ancestor=None):

    if (kind is not None):
        datastore_types.ValidateString(kind, 'kind', datastore_errors.BadArgumentError)
    if (ancestor is not None):
        if (not isinstance(ancestor, entity_pb.Reference)):
            raise datastore_errors.BadArgumentError(('ancestor    argument    should    be    entity_pb.Reference    (%r)' % (ancestor,)))
        if (app is None):
            app = ancestor.app()
        elif (app != ancestor.app()):
            raise datastore_errors.BadArgumentError(('ancestor    argument    should    match    app    ("%r"    !=    "%r")' % (ancestor.app(), app)))
        if (namespace is None):
            namespace = ancestor.name_space()
        elif (namespace != ancestor.name_space()):
            raise datastore_errors.BadArgumentError(('ancestor    argument    should    match    namespace    ("%r"    !=    "%r")' % (ancestor.name_space(), namespace)))
        pb = entity_pb.Reference()
        pb.CopyFrom(ancestor)
        ancestor = pb
        self.__ancestor = ancestor
        self.__path = ancestor.path().element_list()
    else:
        self.__ancestor = None
        self.__path = None
    super(_QueryKeyFilter, self).__init__()
    self.__app = datastore_types.ResolveAppId(app).encode('utf-8')
    self.__namespace = datastore_types.ResolveNamespace(namespace).encode('utf-8')
    self.__kind = (kind and kind.encode('utf-8'))
