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
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
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
1024
1025
1026
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
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
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
977
978
979
980
981
982
983
984
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
980
981
982
983
984
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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
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
987
988
989
990
991
992
993
994
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
990
991
992
993
994
def __call__[**KCellParams, K: ProtoKCell[Any, Any]](
    self, /, **kwargs: Unpack[ModuleCellKWargs]
) -> Callable[[Callable[KCellParams, K]], Callable[KCellParams, K]]:
    """__call__ implementation."""
    ...