Skip to content

synt.stmt.fn ¤

arg module-attribute ¤

arg = FnArg

Alias FnArg.

FnArg ¤

Bases: IntoCode

Function argument.

Examples:

a = arg(id_("foo")).ty(id_("int")).default(litint(1))
assert a.into_code() == "foo: int = 1"
References

arg.

Source code in synt/stmt/fn.py
class FnArg(IntoCode):
    r"""Function argument.

    Examples:
        ```python
        a = arg(id_("foo")).ty(id_("int")).default(litint(1))
        assert a.into_code() == "foo: int = 1"
        ```

    References:
        [`arg`](https://docs.python.org/3/library/ast.html#ast.arg).
    """

    name: Identifier
    """Argument name."""
    annotation: Expression | None
    """Argument annotation."""
    default_expr: Expression | None
    """Argument default expression."""
    is_vararg: bool
    """Whether the argument is a variable argument, or `*args`."""
    is_kwarg: bool
    """Whether the argument is a keyword argument, or `**kwargs`."""

    def __init__(
        self,
        name: Identifier,
        annotation: IntoExpression | None = None,
        default: IntoExpression | None = None,
        is_vararg: bool = False,
        is_kwarg: bool = False,
    ):
        """Initialize a new argument.

        Args:
            name: Argument keyword.
            annotation: Argument annotation.
            default: Default value for the argument.
            is_vararg: Whether the argument is a variable argument, or `*args`.
            is_kwarg: Whether the argument is a keyword argument, or `**kwargs`.
        """
        self.name = name
        self.annotation = (
            annotation.into_expression() if annotation is not None else None
        )
        self.default_expr = default.into_expression() if default is not None else None
        self.is_vararg = is_vararg
        self.is_kwarg = is_kwarg

    def vararg(self) -> Self:
        """Set the argument as a variable argument."""
        self.is_vararg = True
        return self

    def kwarg(self) -> Self:
        """Set the argument as a keyword argument."""
        self.is_kwarg = True
        return self

    def annotate(self, annotation: IntoExpression) -> Self:
        """Add annotation for the argument.

        Args:
            annotation: Argument annotation.
        """
        self.annotation = annotation.into_expression()
        return self

    def ty(self, annotation: IntoExpression) -> Self:
        """Alias [`annotate`][synt.stmt.fn.FnArg.annotate]."""
        return self.annotate(annotation)

    def default(self, default: IntoExpression) -> Self:
        """Set the default value of the argument.

        Args:
            default: Default value for the argument.
        """
        self.default_expr = default.into_expression()
        return self

    def into_code(self) -> str:
        if self.is_vararg:
            name = f"*{self.name.into_code()}"
        elif self.is_kwarg:
            name = f"**{self.name.into_code()}"
        else:
            name = self.name.into_code()
        ret = name
        if self.annotation is not None:
            ret += f": {self.annotation.into_code()}"
        if self.default_expr is not None:
            ret += f" = {self.default_expr.into_code()}"
        return ret

name instance-attribute ¤

name: Identifier = name

Argument name.

annotation instance-attribute ¤

1
2
3
annotation: Expression | None = (
    into_expression() if annotation is not None else None
)

Argument annotation.

default_expr instance-attribute ¤

1
2
3
default_expr: Expression | None = (
    into_expression() if default is not None else None
)

Argument default expression.

is_vararg instance-attribute ¤

is_vararg: bool = is_vararg

Whether the argument is a variable argument, or *args.

is_kwarg instance-attribute ¤

is_kwarg: bool = is_kwarg

Whether the argument is a keyword argument, or **kwargs.

__init__ ¤

1
2
3
4
5
6
7
__init__(
    name: Identifier,
    annotation: IntoExpression | None = None,
    default: IntoExpression | None = None,
    is_vararg: bool = False,
    is_kwarg: bool = False,
)

Initialize a new argument.

Parameters:

Name Type Description Default
name Identifier

Argument keyword.

required
annotation IntoExpression | None

Argument annotation.

None
default IntoExpression | None

Default value for the argument.

None
is_vararg bool

Whether the argument is a variable argument, or *args.

False
is_kwarg bool

Whether the argument is a keyword argument, or **kwargs.

False
Source code in synt/stmt/fn.py
def __init__(
    self,
    name: Identifier,
    annotation: IntoExpression | None = None,
    default: IntoExpression | None = None,
    is_vararg: bool = False,
    is_kwarg: bool = False,
):
    """Initialize a new argument.

    Args:
        name: Argument keyword.
        annotation: Argument annotation.
        default: Default value for the argument.
        is_vararg: Whether the argument is a variable argument, or `*args`.
        is_kwarg: Whether the argument is a keyword argument, or `**kwargs`.
    """
    self.name = name
    self.annotation = (
        annotation.into_expression() if annotation is not None else None
    )
    self.default_expr = default.into_expression() if default is not None else None
    self.is_vararg = is_vararg
    self.is_kwarg = is_kwarg

vararg ¤

vararg() -> Self

Set the argument as a variable argument.

Source code in synt/stmt/fn.py
def vararg(self) -> Self:
    """Set the argument as a variable argument."""
    self.is_vararg = True
    return self

kwarg ¤

kwarg() -> Self

Set the argument as a keyword argument.

Source code in synt/stmt/fn.py
def kwarg(self) -> Self:
    """Set the argument as a keyword argument."""
    self.is_kwarg = True
    return self

annotate ¤

annotate(annotation: IntoExpression) -> Self

Add annotation for the argument.

Parameters:

Name Type Description Default
annotation IntoExpression

Argument annotation.

required
Source code in synt/stmt/fn.py
def annotate(self, annotation: IntoExpression) -> Self:
    """Add annotation for the argument.

    Args:
        annotation: Argument annotation.
    """
    self.annotation = annotation.into_expression()
    return self

ty ¤

ty(annotation: IntoExpression) -> Self

Alias annotate.

Source code in synt/stmt/fn.py
def ty(self, annotation: IntoExpression) -> Self:
    """Alias [`annotate`][synt.stmt.fn.FnArg.annotate]."""
    return self.annotate(annotation)

default ¤

default(default: IntoExpression) -> Self

Set the default value of the argument.

Parameters:

Name Type Description Default
default IntoExpression

Default value for the argument.

required
Source code in synt/stmt/fn.py
def default(self, default: IntoExpression) -> Self:
    """Set the default value of the argument.

    Args:
        default: Default value for the argument.
    """
    self.default_expr = default.into_expression()
    return self

into_code ¤

into_code() -> str
Source code in synt/stmt/fn.py
def into_code(self) -> str:
    if self.is_vararg:
        name = f"*{self.name.into_code()}"
    elif self.is_kwarg:
        name = f"**{self.name.into_code()}"
    else:
        name = self.name.into_code()
    ret = name
    if self.annotation is not None:
        ret += f": {self.annotation.into_code()}"
    if self.default_expr is not None:
        ret += f" = {self.default_expr.into_code()}"
    return ret

FunctionDef ¤

Bases: Statement

Function definition.

Examples:

With dsl-like aliases:

func = (
    dec(id_("foo"))
    .async_def(id_("bar"))[id_("T")](
        id_("a"),
        arg(id_("b")).ty(id_("int")),
        kw=NONE
    ).returns(id_("float")).block(
        return_(ELLIPSIS)
    )
)
assert func.into_code() == "@foo\nasync def bar[T](a, b: int, kw = None) -> float:\n    return ..."
# @foo
# async def bar[T](a, b: int, kw = None) -> float:
#     return ...

With raw ast:

func = (
    dec(id_("foo"))
    .async_def(id_("bar"))
    .type_param(id_("T"))
    .arg(
        id_("a"),
        arg(id_("b")).ty(id_("int")),
        kw=NONE
    )
    .returns(id_("float"))
    .block(
        return_(ELLIPSIS)
    )
)
assert func.into_code() == "@foo\nasync def bar[T](a, b: int, kw = None) -> float:\n    return ..."
# @foo
# async def bar[T](a, b: int, kw = None) -> float:
#     return ...

References

FunctionDef
AsyncFunctionDef

Source code in synt/stmt/fn.py
class FunctionDef(Statement):
    r"""Function definition.

    Examples:
        With dsl-like aliases:
        ```python
        func = (
            dec(id_("foo"))
            .async_def(id_("bar"))[id_("T")](
                id_("a"),
                arg(id_("b")).ty(id_("int")),
                kw=NONE
            ).returns(id_("float")).block(
                return_(ELLIPSIS)
            )
        )
        assert func.into_code() == "@foo\nasync def bar[T](a, b: int, kw = None) -> float:\n    return ..."
        # @foo
        # async def bar[T](a, b: int, kw = None) -> float:
        #     return ...
        ```

        With raw ast:
        ```python
        func = (
            dec(id_("foo"))
            .async_def(id_("bar"))
            .type_param(id_("T"))
            .arg(
                id_("a"),
                arg(id_("b")).ty(id_("int")),
                kw=NONE
            )
            .returns(id_("float"))
            .block(
                return_(ELLIPSIS)
            )
        )
        assert func.into_code() == "@foo\nasync def bar[T](a, b: int, kw = None) -> float:\n    return ..."
        # @foo
        # async def bar[T](a, b: int, kw = None) -> float:
        #     return ...
        ```

    References:
        [`FunctionDef`](https://docs.python.org/3/library/ast.html#ast.FunctionDef)<br/>
        [`AsyncFunctionDef`](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef)
    """

    is_async: bool
    """Whether this function is asynchronous."""
    decorators: list[Expression]
    """Decorators."""
    name: Identifier
    """Function name."""
    type_params: list[TypeParam]
    """Type parameters."""
    args: list[FnArg]
    """Function arguments."""
    returns: Expression | None
    """Return types of the function."""
    body: Block
    """Function body."""

    def __init__(
        self,
        decorators: list[Expression],
        is_async: bool,
        type_params: list[TypeParam],
        args: list[FnArg],
        returns: Expression | None,
        name: Identifier,
        body: Block,
    ):
        """Initialize a function definition.

        **DO NOT USE THIS IN YOUR CODE!**
        """
        self.is_async = is_async
        self.decorators = decorators
        self.type_params = type_params
        self.args = args
        self.returns = returns
        self.name = name
        self.body = body

    def indented(self, indent_width: int, indent_atom: str) -> str:
        indent = indent_width * indent_atom
        decorators = "".join(f"{indent}@{t.into_code()}\n" for t in self.decorators)
        type_param = (
            ""
            if not self.type_params
            else f"[{', '.join(x.into_code() for x in self.type_params)}]"
        )
        args = ", ".join(a.into_code() for a in self.args)
        returns = f" -> {self.returns.into_code()}" if self.returns else ""
        body = self.body.indented(indent_width + 1, indent_atom)
        async_ = "async " if self.is_async else ""
        return f"{decorators}{indent}{async_}def {self.name.into_code()}{type_param}({args}){returns}:\n{body}"

is_async instance-attribute ¤

is_async: bool = is_async

Whether this function is asynchronous.

decorators instance-attribute ¤

decorators: list[Expression] = decorators

Decorators.

type_params instance-attribute ¤

type_params: list[TypeParam] = type_params

Type parameters.

args instance-attribute ¤

args: list[FnArg] = args

Function arguments.

returns instance-attribute ¤

returns: Expression | None = returns

Return types of the function.

name instance-attribute ¤

name: Identifier = name

Function name.

body instance-attribute ¤

body: Block = body

Function body.

__init__ ¤

1
2
3
4
5
6
7
8
9
__init__(
    decorators: list[Expression],
    is_async: bool,
    type_params: list[TypeParam],
    args: list[FnArg],
    returns: Expression | None,
    name: Identifier,
    body: Block,
)

Initialize a function definition.

DO NOT USE THIS IN YOUR CODE!

Source code in synt/stmt/fn.py
def __init__(
    self,
    decorators: list[Expression],
    is_async: bool,
    type_params: list[TypeParam],
    args: list[FnArg],
    returns: Expression | None,
    name: Identifier,
    body: Block,
):
    """Initialize a function definition.

    **DO NOT USE THIS IN YOUR CODE!**
    """
    self.is_async = is_async
    self.decorators = decorators
    self.type_params = type_params
    self.args = args
    self.returns = returns
    self.name = name
    self.body = body

indented ¤

indented(indent_width: int, indent_atom: str) -> str
Source code in synt/stmt/fn.py
def indented(self, indent_width: int, indent_atom: str) -> str:
    indent = indent_width * indent_atom
    decorators = "".join(f"{indent}@{t.into_code()}\n" for t in self.decorators)
    type_param = (
        ""
        if not self.type_params
        else f"[{', '.join(x.into_code() for x in self.type_params)}]"
    )
    args = ", ".join(a.into_code() for a in self.args)
    returns = f" -> {self.returns.into_code()}" if self.returns else ""
    body = self.body.indented(indent_width + 1, indent_atom)
    async_ = "async " if self.is_async else ""
    return f"{decorators}{indent}{async_}def {self.name.into_code()}{type_param}({args}){returns}:\n{body}"

FunctionDefBuilder ¤

Function definition builder.

References

FunctionDef

Source code in synt/stmt/fn.py
class FunctionDefBuilder:
    r"""Function definition builder.

    References:
        [`FunctionDef`][synt.stmt.fn.FunctionDef]
    """

    is_async: bool
    """Whether this function is asynchronous."""
    decorators: list[Expression]
    """Decorators."""
    name: Identifier | None
    """Function name."""
    type_params: list[TypeParam]
    """Type parameters."""
    args: list[FnArg]
    """Function arguments."""
    returns_ty: Expression | None
    """Return types of the function."""

    def __init__(self) -> None:
        """Initialize an empty builder."""
        self.is_async = False
        self.decorators = []
        self.type_params = []
        self.args = []
        self.returns_ty = None
        self.name = None

    def async_(self) -> Self:
        """Set this function as asynchronous."""
        self.is_async = True
        return self

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

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

    def dec(self, decorator: IntoExpression) -> Self:
        """Alias [synt.stmt.fn.FunctionDefBuilder.decorator]."""
        return self.decorator(decorator)

    def def_(self, name: Identifier) -> Self:
        """Initialize a function.

        Args:
            name: Function name.
        """
        self.name = name
        return self

    def async_def(self, name: Identifier) -> Self:
        """Initialize an async function.

        This is equivalent to `self.async_().def_(name)`.

        Args:
            name: Function name.
        """
        return self.async_().def_(name)

    def type_param(self, *args: TypeParam | Identifier) -> Self:
        """Add generic type parameters.

        Args:
            *args: Type parameters to add.
        """
        from synt.tokens.ident import Identifier

        self.type_params = [
            TypeVar(x) if isinstance(x, Identifier) else x for x in args
        ]
        return self

    def ty(self, *args: TypeParam | Identifier) -> Self:
        """Alias [`type_param`][synt.stmt.fn.FunctionDefBuilder.type_param]."""
        return self.type_param(*args)

    def __getitem__(
        self, items: tuple[TypeParam | Identifier, ...] | TypeParam | Identifier
    ) -> Self:
        """Alias [`type_param`][synt.stmt.fn.FunctionDefBuilder.type_param]."""
        if isinstance(items, tuple):
            return self.type_param(*items)
        else:
            return self.type_param(items)

    def arg(self, *args: FnArg | Identifier, **kwargs: IntoExpression) -> Self:
        """Add arguments for the function.

        Args:
            *args: Arguments to add.
            **kwargs: Keyword arguments to add with their default values.
        """
        from synt.tokens.ident import Identifier

        self.args = []
        for a in args:
            if isinstance(a, Identifier):
                self.args.append(FnArg(a))
            else:
                self.args.append(a)
        for k, v in kwargs.items():
            self.args.append(FnArg(Identifier(k), default=v.into_expression()))
        return self

    def __call__(self, *args: FnArg | Identifier, **kwargs: IntoExpression) -> Self:
        """Alias [`arg`][synt.stmt.fn.FunctionDefBuilder.arg]."""
        return self.arg(*args, **kwargs)

    def returns(self, returns: IntoExpression) -> Self:
        """Set the return type of the function.

        Args:
            returns: Return type of the function.
        """
        self.returns_ty = returns.into_expression()
        return self

    def block(self, *statements: Statement) -> FunctionDef:
        """Set the block of the function, and build it.

        Args:
            *statements: Statements to include in the function body.

        Raises:
            ValueError: If the required fields (`[name,]`) are not set.
        """
        err_fields = []
        if self.name is None:
            err_fields.append("name")

        if err_fields:
            raise ValueError(
                f"Missing required fields: {', '.join(f'`{t}`' for t in err_fields)}"
            )

        return FunctionDef(
            decorators=self.decorators,
            is_async=self.is_async,
            type_params=self.type_params,
            args=self.args,
            returns=self.returns_ty,
            name=self.name,  # type:ignore[arg-type]
            body=Block(*statements),
        )

is_async instance-attribute ¤

is_async: bool = False

Whether this function is asynchronous.

decorators instance-attribute ¤

decorators: list[Expression] = []

Decorators.

type_params instance-attribute ¤

type_params: list[TypeParam] = []

Type parameters.

args instance-attribute ¤

args: list[FnArg] = []

Function arguments.

returns_ty instance-attribute ¤

returns_ty: Expression | None = None

Return types of the function.

name instance-attribute ¤

name: Identifier | None = None

Function name.

__init__ ¤

__init__() -> None

Initialize an empty builder.

Source code in synt/stmt/fn.py
def __init__(self) -> None:
    """Initialize an empty builder."""
    self.is_async = False
    self.decorators = []
    self.type_params = []
    self.args = []
    self.returns_ty = None
    self.name = None

async_ ¤

async_() -> Self

Set this function as asynchronous.

Source code in synt/stmt/fn.py
def async_(self) -> Self:
    """Set this function as asynchronous."""
    self.is_async = True
    return self

decorator ¤

decorator(decorator: IntoExpression) -> Self

Append a decorator.

Parameters:

Name Type Description Default
decorator IntoExpression

Decorator to append.

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

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

dec ¤

dec(decorator: IntoExpression) -> Self

Alias [synt.stmt.fn.FunctionDefBuilder.decorator].

Source code in synt/stmt/fn.py
def dec(self, decorator: IntoExpression) -> Self:
    """Alias [synt.stmt.fn.FunctionDefBuilder.decorator]."""
    return self.decorator(decorator)

def_ ¤

def_(name: Identifier) -> Self

Initialize a function.

Parameters:

Name Type Description Default
name Identifier

Function name.

required
Source code in synt/stmt/fn.py
def def_(self, name: Identifier) -> Self:
    """Initialize a function.

    Args:
        name: Function name.
    """
    self.name = name
    return self

async_def ¤

async_def(name: Identifier) -> Self

Initialize an async function.

This is equivalent to self.async_().def_(name).

Parameters:

Name Type Description Default
name Identifier

Function name.

required
Source code in synt/stmt/fn.py
def async_def(self, name: Identifier) -> Self:
    """Initialize an async function.

    This is equivalent to `self.async_().def_(name)`.

    Args:
        name: Function name.
    """
    return self.async_().def_(name)

type_param ¤

type_param(*args: TypeParam | Identifier) -> Self

Add generic type parameters.

Parameters:

Name Type Description Default
*args TypeParam | Identifier

Type parameters to add.

()
Source code in synt/stmt/fn.py
def type_param(self, *args: TypeParam | Identifier) -> Self:
    """Add generic type parameters.

    Args:
        *args: Type parameters to add.
    """
    from synt.tokens.ident import Identifier

    self.type_params = [
        TypeVar(x) if isinstance(x, Identifier) else x for x in args
    ]
    return self

ty ¤

ty(*args: TypeParam | Identifier) -> Self

Alias type_param.

Source code in synt/stmt/fn.py
def ty(self, *args: TypeParam | Identifier) -> Self:
    """Alias [`type_param`][synt.stmt.fn.FunctionDefBuilder.type_param]."""
    return self.type_param(*args)

__getitem__ ¤

1
2
3
4
5
6
7
__getitem__(
    items: (
        tuple[TypeParam | Identifier, ...]
        | TypeParam
        | Identifier
    )
) -> Self

Alias type_param.

Source code in synt/stmt/fn.py
def __getitem__(
    self, items: tuple[TypeParam | Identifier, ...] | TypeParam | Identifier
) -> Self:
    """Alias [`type_param`][synt.stmt.fn.FunctionDefBuilder.type_param]."""
    if isinstance(items, tuple):
        return self.type_param(*items)
    else:
        return self.type_param(items)

arg ¤

1
2
3
arg(
    *args: FnArg | Identifier, **kwargs: IntoExpression
) -> Self

Add arguments for the function.

Parameters:

Name Type Description Default
*args FnArg | Identifier

Arguments to add.

()
**kwargs IntoExpression

Keyword arguments to add with their default values.

{}
Source code in synt/stmt/fn.py
def arg(self, *args: FnArg | Identifier, **kwargs: IntoExpression) -> Self:
    """Add arguments for the function.

    Args:
        *args: Arguments to add.
        **kwargs: Keyword arguments to add with their default values.
    """
    from synt.tokens.ident import Identifier

    self.args = []
    for a in args:
        if isinstance(a, Identifier):
            self.args.append(FnArg(a))
        else:
            self.args.append(a)
    for k, v in kwargs.items():
        self.args.append(FnArg(Identifier(k), default=v.into_expression()))
    return self

__call__ ¤

1
2
3
__call__(
    *args: FnArg | Identifier, **kwargs: IntoExpression
) -> Self

Alias arg.

Source code in synt/stmt/fn.py
def __call__(self, *args: FnArg | Identifier, **kwargs: IntoExpression) -> Self:
    """Alias [`arg`][synt.stmt.fn.FunctionDefBuilder.arg]."""
    return self.arg(*args, **kwargs)

returns ¤

returns(returns: IntoExpression) -> Self

Set the return type of the function.

Parameters:

Name Type Description Default
returns IntoExpression

Return type of the function.

required
Source code in synt/stmt/fn.py
def returns(self, returns: IntoExpression) -> Self:
    """Set the return type of the function.

    Args:
        returns: Return type of the function.
    """
    self.returns_ty = returns.into_expression()
    return self

block ¤

block(*statements: Statement) -> FunctionDef

Set the block of the function, and build it.

Parameters:

Name Type Description Default
*statements Statement

Statements to include in the function body.

()

Raises:

Type Description
ValueError

If the required fields ([name,]) are not set.

Source code in synt/stmt/fn.py
def block(self, *statements: Statement) -> FunctionDef:
    """Set the block of the function, and build it.

    Args:
        *statements: Statements to include in the function body.

    Raises:
        ValueError: If the required fields (`[name,]`) are not set.
    """
    err_fields = []
    if self.name is None:
        err_fields.append("name")

    if err_fields:
        raise ValueError(
            f"Missing required fields: {', '.join(f'`{t}`' for t in err_fields)}"
        )

    return FunctionDef(
        decorators=self.decorators,
        is_async=self.is_async,
        type_params=self.type_params,
        args=self.args,
        returns=self.returns_ty,
        name=self.name,  # type:ignore[arg-type]
        body=Block(*statements),
    )

vararg ¤

vararg(i: Identifier) -> FnArg

Initialize a variable argument.

This is equivalent to FnArg(...).vararg().

Examples:

va = vararg(id_("foo")).ty(id_("int"))
assert va.into_code() == "*foo: int"
Source code in synt/stmt/fn.py
def vararg(i: Identifier) -> FnArg:
    r"""Initialize a variable argument.

    This is equivalent to `FnArg(...).vararg()`.

    Examples:
        ```python
        va = vararg(id_("foo")).ty(id_("int"))
        assert va.into_code() == "*foo: int"
        ```
    """
    return FnArg(i).vararg()

kwarg ¤

kwarg(i: Identifier) -> FnArg

Initialize a keyword argument.

This is equivalent to FnArg(...).kwarg().

Examples:

va = kwarg(id_("foo")).ty(id_("tuple").expr()[id_("str"), id_("int")])
assert va.into_code() == "**foo: tuple[str, int]"
Source code in synt/stmt/fn.py
def kwarg(i: Identifier) -> FnArg:
    r"""Initialize a keyword argument.

    This is equivalent to `FnArg(...).kwarg()`.

    Examples:
        ```python
        va = kwarg(id_("foo")).ty(id_("tuple").expr()[id_("str"), id_("int")])
        assert va.into_code() == "**foo: tuple[str, int]"
        ```
    """
    return FnArg(i).kwarg()

def_ ¤

Initialize a function definition.

Parameters:

Name Type Description Default
name Identifier

Function name.

required
Source code in synt/stmt/fn.py
def def_(name: Identifier) -> FunctionDefBuilder:
    r"""Initialize a function definition.

    Args:
        name: Function name.
    """
    return FunctionDefBuilder().def_(name)

async_def ¤

async_def(name: Identifier) -> FunctionDefBuilder

Initialize an async function definition.

Parameters:

Name Type Description Default
name Identifier

Function name.

required
Source code in synt/stmt/fn.py
def async_def(name: Identifier) -> FunctionDefBuilder:
    r"""Initialize an async function definition.

    Args:
        name: Function name.
    """
    return FunctionDefBuilder().async_def(name)