예제 #1
0
파일: pathid.py 프로젝트: sthagen/edgedb
    def from_pointer(
            cls,
            schema: s_schema.Schema,
            pointer: s_pointers.Pointer,
            *,
            namespace: AbstractSet[AnyNamespace] = frozenset(),
    ) -> PathId:
        """Return a ``PathId`` instance for a given link or property.

        The specified *pointer* argument must be a concrete link or property.
        The returned ``PathId`` instance describes a set variable of all
        objects represented by the pointer (i.e, for a link, a set of all
        link targets).

        Args:
            schema:
                A schema instance where the type *t* is defined.
            pointer:
                An instance of a concrete link or property.
            namespace:
                Optional namespace in which the variable is defined.

        Returns:
            A ``PathId`` instance.
        """
        if pointer.generic(schema):
            raise ValueError(f'invalid PathId: {pointer} is not concrete')

        source = pointer.get_source(schema)
        if isinstance(source, s_pointers.Pointer):
            prefix = cls.from_pointer(schema, source, namespace=namespace)
            prefix = prefix.ptr_path()
        elif isinstance(source, s_types.Type):
            prefix = cls.from_type(schema, source, namespace=namespace)
        else:
            raise AssertionError(f'unexpected pointer source: {source!r}')

        ptrref = typeutils.ptrref_from_ptrcls(schema=schema, ptrcls=pointer)
        return prefix.extend(ptrref=ptrref)
예제 #2
0
def get_pointer_path_id(ptr: s_pointers.Pointer, *,
                        ctx: context.ContextLevel) -> irast.PathId:
    src = ptr.get_source(ctx.env.schema)
    assert isinstance(src, s_types.Type)
    return extend_path_id(get_path_id(src, ctx=ctx), ptrcls=ptr, ctx=ctx)