Skip to content

synt.stmt.decorator ¤

dec module-attribute ¤

DecoratorGroup ¤

A group of decorators.

Source code in synt/stmt/decorator.py
class DecoratorGroup:
    r"""A group of decorators."""

    decorators: list[Expression]
    """Decorators."""

    def __init__(self, decorator: IntoExpression):
        """Initialize a decorator and create a new group.

        Args:
            decorator: The decorator to add.
        """
        self.decorators = [decorator.into_expression()]

    def dec(self, decorator: IntoExpression) -> Self:
        """Append a new decorator.

        Args:
            decorator: The decorator to add.
        """
        self.decorators.append(decorator.into_expression())
        return self

    def class_(self, name: Identifier) -> ClassDefBuilder:
        """Initialize a class with the decorators.

        Args:
            name: The name of the class.
        """
        cls = ClassDefBuilder()
        cls.decorators = self.decorators
        return cls.class_(name)

    def def_(self, name: Identifier) -> FunctionDefBuilder:
        """Initialize a function with the decorators.

        Args:
            name: The name of the function.
        """
        fn = FunctionDefBuilder()
        fn.decorators = self.decorators
        return fn.def_(name)

    def async_def(self, name: Identifier) -> FunctionDefBuilder:
        """Initialize an async function with the decorators.

        Args:
            name: The name of the function.
        """
        return self.def_(name).async_()

decorators instance-attribute ¤

decorators: list[Expression] = [into_expression()]

Decorators.

__init__ ¤

__init__(decorator: IntoExpression)

Initialize a decorator and create a new group.

Parameters:

Name Type Description Default
decorator IntoExpression

The decorator to add.

required
Source code in synt/stmt/decorator.py
def __init__(self, decorator: IntoExpression):
    """Initialize a decorator and create a new group.

    Args:
        decorator: The decorator to add.
    """
    self.decorators = [decorator.into_expression()]

dec ¤

dec(decorator: IntoExpression) -> Self

Append a new decorator.

Parameters:

Name Type Description Default
decorator IntoExpression

The decorator to add.

required
Source code in synt/stmt/decorator.py
def dec(self, decorator: IntoExpression) -> Self:
    """Append a new decorator.

    Args:
        decorator: The decorator to add.
    """
    self.decorators.append(decorator.into_expression())
    return self

class_ ¤

class_(name: Identifier) -> ClassDefBuilder

Initialize a class with the decorators.

Parameters:

Name Type Description Default
name Identifier

The name of the class.

required
Source code in synt/stmt/decorator.py
def class_(self, name: Identifier) -> ClassDefBuilder:
    """Initialize a class with the decorators.

    Args:
        name: The name of the class.
    """
    cls = ClassDefBuilder()
    cls.decorators = self.decorators
    return cls.class_(name)

def_ ¤

Initialize a function with the decorators.

Parameters:

Name Type Description Default
name Identifier

The name of the function.

required
Source code in synt/stmt/decorator.py
def def_(self, name: Identifier) -> FunctionDefBuilder:
    """Initialize a function with the decorators.

    Args:
        name: The name of the function.
    """
    fn = FunctionDefBuilder()
    fn.decorators = self.decorators
    return fn.def_(name)

async_def ¤

async_def(name: Identifier) -> FunctionDefBuilder

Initialize an async function with the decorators.

Parameters:

Name Type Description Default
name Identifier

The name of the function.

required
Source code in synt/stmt/decorator.py
def async_def(self, name: Identifier) -> FunctionDefBuilder:
    """Initialize an async function with the decorators.

    Args:
        name: The name of the function.
    """
    return self.def_(name).async_()