Skip to content

synt.expr.call ¤

Call ¤

Bases: Expression

Calling a value.

References

Call.

Source code in synt/expr/call.py
class Call(expr.Expression):
    r"""Calling a value.

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

    target: expr.Expression
    """Call target."""
    args: list[expr.Expression]
    """Positional arguments of the call."""
    keywords: list[Keyword]
    """Keyword arguments of the call."""

    precedence = expr.ExprPrecedence.Call
    expr_type = expr.ExprType.Call

    def __init__(
        self,
        target: expr.IntoExpression,
        args: list[expr.IntoExpression],
        keywords: list[Keyword],
    ):
        """Initialize a new `Call`.

        Args:
            target: Call target.
            args: Positional arguments of the call.
            keywords: Keyword arguments of the call.
        """
        self.target = target.into_expression()
        if self.target.precedence > self.precedence:
            self.target = self.target.wrapped()

        self.args = [arg.into_expression() for arg in args]
        self.keywords = keywords

    def into_code(self) -> str:
        arg_text = ""
        if self.args:
            args_text = ", ".join(arg.into_code() for arg in self.args)
            if self.keywords:
                kwargs_text = ", ".join(kw.into_code() for kw in self.keywords)
                arg_text = f"{args_text}, {kwargs_text}"
            else:
                arg_text = args_text
        elif self.keywords:
            arg_text = ", ".join(kw.into_code() for kw in self.keywords)

        return f"{self.target.into_code()}({arg_text})"

precedence class-attribute instance-attribute ¤

precedence = Call

expr_type class-attribute instance-attribute ¤

expr_type = Call

target instance-attribute ¤

target: Expression = into_expression()

Call target.

args instance-attribute ¤

args: list[Expression] = [into_expression() for arg in args]

Positional arguments of the call.

keywords instance-attribute ¤

keywords: list[Keyword] = keywords

Keyword arguments of the call.

__init__ ¤

1
2
3
4
5
__init__(
    target: IntoExpression,
    args: list[IntoExpression],
    keywords: list[Keyword],
)

Initialize a new Call.

Parameters:

Name Type Description Default
target IntoExpression

Call target.

required
args list[IntoExpression]

Positional arguments of the call.

required
keywords list[Keyword]

Keyword arguments of the call.

required
Source code in synt/expr/call.py
def __init__(
    self,
    target: expr.IntoExpression,
    args: list[expr.IntoExpression],
    keywords: list[Keyword],
):
    """Initialize a new `Call`.

    Args:
        target: Call target.
        args: Positional arguments of the call.
        keywords: Keyword arguments of the call.
    """
    self.target = target.into_expression()
    if self.target.precedence > self.precedence:
        self.target = self.target.wrapped()

    self.args = [arg.into_expression() for arg in args]
    self.keywords = keywords

into_code ¤

into_code() -> str
Source code in synt/expr/call.py
def into_code(self) -> str:
    arg_text = ""
    if self.args:
        args_text = ", ".join(arg.into_code() for arg in self.args)
        if self.keywords:
            kwargs_text = ", ".join(kw.into_code() for kw in self.keywords)
            arg_text = f"{args_text}, {kwargs_text}"
        else:
            arg_text = args_text
    elif self.keywords:
        arg_text = ", ".join(kw.into_code() for kw in self.keywords)

    return f"{self.target.into_code()}({arg_text})"

Keyword ¤

Bases: IntoCode

Keyword arguments of a object call.

References

Call Keyword(PythonAst)

Source code in synt/expr/call.py
class Keyword(code.IntoCode):
    r"""Keyword arguments of a object call.

    References:
        [`Call`][synt.expr.call.Call]
        [`Keyword`(PythonAst)](https://docs.python.org/3/library/ast.html#ast.keyword)
    """

    key: Identifier
    """Keyword."""
    value: expr.Expression
    """Value for the argument."""

    def __init__(self, key: Identifier, value: expr.IntoExpression):
        """Initialize a new keyword argument.

        Args:
            key: Keyword.
            value: Value for the argument.
        """
        self.key = key
        self.value = value.into_expression()

    def into_code(self) -> str:
        return f"{self.key.into_code()}={self.value.into_code()}"

key instance-attribute ¤

Keyword.

value instance-attribute ¤

value: Expression = into_expression()

Value for the argument.

__init__ ¤

__init__(key: Identifier, value: IntoExpression)

Initialize a new keyword argument.

Parameters:

Name Type Description Default
key Identifier

Keyword.

required
value IntoExpression

Value for the argument.

required
Source code in synt/expr/call.py
def __init__(self, key: Identifier, value: expr.IntoExpression):
    """Initialize a new keyword argument.

    Args:
        key: Keyword.
        value: Value for the argument.
    """
    self.key = key
    self.value = value.into_expression()

into_code ¤

into_code() -> str
Source code in synt/expr/call.py
def into_code(self) -> str:
    return f"{self.key.into_code()}={self.value.into_code()}"