Skip to content

Decorators

decorators

Defines additional decorators than just @cell.

Decorators

Various decorators intended to be attached to a KCLayout.

Source code in kfactory/decorators.py
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
class Decorators:
    """Various decorators intended to be attached to a KCLayout."""

    def __init__(self, kcl: KCLayout) -> None:
        """Just set the standard `@cell` decorator."""
        self._cell = kcl.cell

    @overload
    def module_cell[**KCellParams, KC: ProtoTKCell[Any]](
        self,
        _func: Callable[KCellParams, KC],
        /,
    ) -> Callable[KCellParams, KC]: ...

    @overload
    def module_cell[**KCellParams, KC: ProtoTKCell[Any]](
        self, /, **kwargs: Unpack[ModuleCellKWargs]
    ) -> Callable[[Callable[KCellParams, KC]], Callable[KCellParams, KC]]: ...

    def module_cell[**KCellParams, KC: ProtoTKCell[Any]](
        self,
        _func: Callable[KCellParams, KC] | None = None,
        /,
        **kwargs: Unpack[ModuleCellKWargs],
    ) -> (
        Callable[KCellParams, KC]
        | Callable[[Callable[KCellParams, KC]], Callable[KCellParams, KC]]
    ):
        """Constructs the `@module_cell` decorator on KCLayout.decorators."""

        def mc(
            **kwargs: Unpack[ModuleCellKWargs],
        ) -> Callable[[Callable[KCellParams, KC]], Callable[KCellParams, KC]]:
            return _module_cell(self._cell, **kwargs)  # ty:ignore[invalid-argument-type]

        return mc(**kwargs) if _func is None else mc(**kwargs)(_func)

__init__

__init__(kcl: KCLayout) -> None

Just set the standard @cell decorator.

Source code in kfactory/decorators.py
948
949
950
def __init__(self, kcl: KCLayout) -> None:
    """Just set the standard `@cell` decorator."""
    self._cell = kcl.cell

module_cell

module_cell(
    _func: Callable[KCellParams, KC],
) -> Callable[KCellParams, KC]
module_cell(
    **kwargs: Unpack[ModuleCellKWargs],
) -> Callable[
    [Callable[KCellParams, KC]], Callable[KCellParams, KC]
]
module_cell(
    _func: Callable[KCellParams, KC] | None = None,
    /,
    **kwargs: Unpack[ModuleCellKWargs],
) -> (
    Callable[KCellParams, KC]
    | Callable[
        [Callable[KCellParams, KC]],
        Callable[KCellParams, KC],
    ]
)

Constructs the @module_cell decorator on KCLayout.decorators.

Source code in kfactory/decorators.py
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
def module_cell[**KCellParams, KC: ProtoTKCell[Any]](
    self,
    _func: Callable[KCellParams, KC] | None = None,
    /,
    **kwargs: Unpack[ModuleCellKWargs],
) -> (
    Callable[KCellParams, KC]
    | Callable[[Callable[KCellParams, KC]], Callable[KCellParams, KC]]
):
    """Constructs the `@module_cell` decorator on KCLayout.decorators."""

    def mc(
        **kwargs: Unpack[ModuleCellKWargs],
    ) -> Callable[[Callable[KCellParams, KC]], Callable[KCellParams, KC]]:
        return _module_cell(self._cell, **kwargs)  # ty:ignore[invalid-argument-type]

    return mc(**kwargs) if _func is None else mc(**kwargs)(_func)

KCellDecorator

Bases: Protocol

Signature of the @cell decorator.

Source code in kfactory/decorators.py
901
902
903
904
905
906
907
908
class KCellDecorator[**KCellParams, K: ProtoKCell[Any, Any]](Protocol):
    """Signature of the `@cell` decorator."""

    def __call__(
        self, **kwargs: Unpack[KCellDecoratorKWargs]
    ) -> Callable[[Callable[KCellParams, K]], Callable[KCellParams, K]]:
        """__call__ implementation."""
        ...

__call__

__call__(
    **kwargs: Unpack[KCellDecoratorKWargs],
) -> Callable[
    [Callable[KCellParams, K]], Callable[KCellParams, K]
]

call implementation.

Source code in kfactory/decorators.py
904
905
906
907
908
def __call__(
    self, **kwargs: Unpack[KCellDecoratorKWargs]
) -> Callable[[Callable[KCellParams, K]], Callable[KCellParams, K]]:
    """__call__ implementation."""
    ...

KCellDecoratorKWargs

Bases: TypedDict

KWargs for @cell.

Source code in kfactory/decorators.py
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
class KCellDecoratorKWargs(TypedDict, total=False):
    """KWargs for `@cell`."""

    set_settings: bool
    set_name: bool
    check_ports: bool
    check_pins: bool
    check_instances: CheckInstances | None
    snap_ports: bool
    add_port_layers: bool
    cache: Cache[int, Any] | dict[int, Any] | None
    basename: str | None
    drop_params: list[str]
    register_factory: bool
    overwrite_existing: bool | None
    layout_cache: bool | None
    info: dict[str, MetaData] | None
    post_process: Iterable[Callable[[TKCell], None]]
    debug_names: bool | None

ModuleCellKWargs

Bases: TypedDict

KWargs for @module_cell.

Source code in kfactory/decorators.py
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
class ModuleCellKWargs(TypedDict, total=False):
    """KWargs for `@module_cell`."""

    set_settings: bool
    set_name: bool
    check_ports: bool
    check_pins: bool
    check_instances: CheckInstances | None
    snap_ports: bool
    add_port_layers: bool
    cache: Cache[int, Any] | dict[int, Any] | None
    drop_params: list[str]
    register_factory: bool
    overwrite_existing: bool | None
    layout_cache: bool | None
    info: dict[str, MetaData] | None
    post_process: Iterable[Callable[[TKCell], None]]
    debug_names: bool | None

ModuleDecorator

Bases: Protocol

Signature of the @module_cell decorator.

Source code in kfactory/decorators.py
911
912
913
914
915
916
917
918
class ModuleDecorator(Protocol):
    """Signature of the `@module_cell` decorator."""

    def __call__[**KCellParams, K: ProtoKCell[Any, Any]](
        self, /, **kwargs: Unpack[ModuleCellKWargs]
    ) -> Callable[[Callable[KCellParams, K]], Callable[KCellParams, K]]:
        """__call__ implementation."""
        ...

__call__

__call__(
    **kwargs: Unpack[ModuleCellKWargs],
) -> Callable[
    [Callable[KCellParams, K]], Callable[KCellParams, K]
]

call implementation.

Source code in kfactory/decorators.py
914
915
916
917
918
def __call__[**KCellParams, K: ProtoKCell[Any, Any]](
    self, /, **kwargs: Unpack[ModuleCellKWargs]
) -> Callable[[Callable[KCellParams, K]], Callable[KCellParams, K]]:
    """__call__ implementation."""
    ...