Skip to content

robot.parsing.model.statements

Statement

1
2
3
Statement(
    tokens: Sequence[Token], errors: Sequence[str] = ()
)

Bases: Node, ABC

Source code in src/robot/parsing/model/statements.py
def __init__(self, tokens: 'Sequence[Token]', errors: 'Sequence[str]' = ()):
    self.tokens = tuple(tokens)
    self.errors = tuple(errors)

from_tokens classmethod

from_tokens(tokens: Sequence[Token]) -> Statement

Create a statement from given tokens.

Statement type is got automatically from token types.

This classmethod should be called from :class:Statement, not from its subclasses. If you know the subclass to use, simply create an instance of it directly.

Source code in src/robot/parsing/model/statements.py
@classmethod
def from_tokens(cls, tokens: 'Sequence[Token]') -> 'Statement':
    """Create a statement from given tokens.

    Statement type is got automatically from token types.

    This classmethod should be called from :class:`Statement`, not from
    its subclasses. If you know the subclass to use, simply create an
    instance of it directly.
    """
    handlers = cls.statement_handlers
    for token in tokens:
        if token.type in handlers:
            return handlers[token.type](tokens)
    if any(token.type == Token.ASSIGN for token in tokens):
        return KeywordCall(tokens)
    return EmptyLine(tokens)

from_params abstractmethod classmethod

from_params(*args, **kwargs) -> Statement

Create a statement from passed parameters.

Required and optional arguments in general match class properties. Values are used to create matching tokens.

Most implementations support following general properties:

  • separator whitespace inserted between each token. Default is four spaces.
  • indent whitespace inserted before first token. Default is four spaces.
  • eol end of line sign. Default is '\n'.

This classmethod should be called from the :class:Statement subclass to create, not from the :class:Statement class itself.

Source code in src/robot/parsing/model/statements.py
@classmethod
@abstractmethod
def from_params(cls, *args, **kwargs) -> 'Statement':
    """Create a statement from passed parameters.

    Required and optional arguments in general match class properties.
    Values are used to create matching tokens.

    Most implementations support following general properties:

    - ``separator`` whitespace inserted between each token. Default is four spaces.
    - ``indent`` whitespace inserted before first token. Default is four spaces.
    - ``eol`` end of line sign. Default is ``'\\n'``.

    This classmethod should be called from the :class:`Statement` subclass
    to create, not from the :class:`Statement` class itself.
    """
    raise NotImplementedError

get_token

get_token(*types: str) -> Token | None

Return a token with any of the given types.

If there are no matches, return None. If there are multiple matches, return the first match.

Source code in src/robot/parsing/model/statements.py
def get_token(self, *types: str) -> 'Token|None':
    """Return a token with any of the given ``types``.

    If there are no matches, return ``None``. If there are multiple
    matches, return the first match.
    """
    for token in self.tokens:
        if token.type in types:
            return token
    return None

get_tokens

get_tokens(*types: str) -> list[Token]

Return tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_tokens(self, *types: str) -> 'list[Token]':
    """Return tokens having any of the given ``types``."""
    return [t for t in self.tokens if t.type in types]

get_value

get_value(type: str, default: str) -> str
get_value(type: str, default: None = None) -> str | None
1
2
3
get_value(
    type: str, default: str | None = None
) -> str | None

Return value of a token with the given type.

If there are no matches, return default. If there are multiple matches, return the value of the first match.

Source code in src/robot/parsing/model/statements.py
def get_value(self, type: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a token with the given ``type``.

    If there are no matches, return ``default``. If there are multiple
    matches, return the value of the first match.
    """
    token = self.get_token(type)
    return token.value if token else default

get_values

get_values(*types: str) -> tuple[str, ...]

Return values of tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_values(self, *types: str) -> 'tuple[str, ...]':
    """Return values of tokens having any of the given ``types``."""
    return tuple(t.value for t in self.tokens if t.type in types)

get_option

1
2
3
get_option(
    name: str, default: str | None = None
) -> str | None

Return value of a configuration option with the given name.

If the option has not been used, return default.

If the option has been used multiple times, values are joined together. This is typically an error situation and validated elsewhere.

New in Robot Framework 6.1.

Source code in src/robot/parsing/model/statements.py
def get_option(self, name: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a configuration option with the given ``name``.

    If the option has not been used, return ``default``.

    If the option has been used multiple times, values are joined together.
    This is typically an error situation and validated elsewhere.

    New in Robot Framework 6.1.
    """
    return self._get_options().get(name, default)

ReturnSetting

1
2
3
ReturnSetting(
    tokens: Sequence[Token], errors: Sequence[str] = ()
)

Bases: MultiValue

Represents the deprecated [Return] setting.

This class was named Return prior to Robot Framework 7.0. A forward compatible ReturnSetting alias existed already in Robot Framework 6.1.

Source code in src/robot/parsing/model/statements.py
def __init__(self, tokens: 'Sequence[Token]', errors: 'Sequence[str]' = ()):
    self.tokens = tuple(tokens)
    self.errors = tuple(errors)

from_tokens classmethod

from_tokens(tokens: Sequence[Token]) -> Statement

Create a statement from given tokens.

Statement type is got automatically from token types.

This classmethod should be called from :class:Statement, not from its subclasses. If you know the subclass to use, simply create an instance of it directly.

Source code in src/robot/parsing/model/statements.py
@classmethod
def from_tokens(cls, tokens: 'Sequence[Token]') -> 'Statement':
    """Create a statement from given tokens.

    Statement type is got automatically from token types.

    This classmethod should be called from :class:`Statement`, not from
    its subclasses. If you know the subclass to use, simply create an
    instance of it directly.
    """
    handlers = cls.statement_handlers
    for token in tokens:
        if token.type in handlers:
            return handlers[token.type](tokens)
    if any(token.type == Token.ASSIGN for token in tokens):
        return KeywordCall(tokens)
    return EmptyLine(tokens)

get_token

get_token(*types: str) -> Token | None

Return a token with any of the given types.

If there are no matches, return None. If there are multiple matches, return the first match.

Source code in src/robot/parsing/model/statements.py
def get_token(self, *types: str) -> 'Token|None':
    """Return a token with any of the given ``types``.

    If there are no matches, return ``None``. If there are multiple
    matches, return the first match.
    """
    for token in self.tokens:
        if token.type in types:
            return token
    return None

get_tokens

get_tokens(*types: str) -> list[Token]

Return tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_tokens(self, *types: str) -> 'list[Token]':
    """Return tokens having any of the given ``types``."""
    return [t for t in self.tokens if t.type in types]

get_value

get_value(type: str, default: str) -> str
get_value(type: str, default: None = None) -> str | None
1
2
3
get_value(
    type: str, default: str | None = None
) -> str | None

Return value of a token with the given type.

If there are no matches, return default. If there are multiple matches, return the value of the first match.

Source code in src/robot/parsing/model/statements.py
def get_value(self, type: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a token with the given ``type``.

    If there are no matches, return ``default``. If there are multiple
    matches, return the value of the first match.
    """
    token = self.get_token(type)
    return token.value if token else default

get_values

get_values(*types: str) -> tuple[str, ...]

Return values of tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_values(self, *types: str) -> 'tuple[str, ...]':
    """Return values of tokens having any of the given ``types``."""
    return tuple(t.value for t in self.tokens if t.type in types)

get_option

1
2
3
get_option(
    name: str, default: str | None = None
) -> str | None

Return value of a configuration option with the given name.

If the option has not been used, return default.

If the option has been used multiple times, values are joined together. This is typically an error situation and validated elsewhere.

New in Robot Framework 6.1.

Source code in src/robot/parsing/model/statements.py
def get_option(self, name: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a configuration option with the given ``name``.

    If the option has not been used, return ``default``.

    If the option has been used multiple times, values are joined together.
    This is typically an error situation and validated elsewhere.

    New in Robot Framework 6.1.
    """
    return self._get_options().get(name, default)

Return

Return(tokens: Sequence[Token], errors: Sequence[str] = ())

Bases: Statement

Represents the RETURN statement.

This class named ReturnStatement prior to Robot Framework 7.0. The old name still exists as a backwards compatible alias.

Source code in src/robot/parsing/model/statements.py
def __init__(self, tokens: 'Sequence[Token]', errors: 'Sequence[str]' = ()):
    self.tokens = tuple(tokens)
    self.errors = tuple(errors)

from_tokens classmethod

from_tokens(tokens: Sequence[Token]) -> Statement

Create a statement from given tokens.

Statement type is got automatically from token types.

This classmethod should be called from :class:Statement, not from its subclasses. If you know the subclass to use, simply create an instance of it directly.

Source code in src/robot/parsing/model/statements.py
@classmethod
def from_tokens(cls, tokens: 'Sequence[Token]') -> 'Statement':
    """Create a statement from given tokens.

    Statement type is got automatically from token types.

    This classmethod should be called from :class:`Statement`, not from
    its subclasses. If you know the subclass to use, simply create an
    instance of it directly.
    """
    handlers = cls.statement_handlers
    for token in tokens:
        if token.type in handlers:
            return handlers[token.type](tokens)
    if any(token.type == Token.ASSIGN for token in tokens):
        return KeywordCall(tokens)
    return EmptyLine(tokens)

get_token

get_token(*types: str) -> Token | None

Return a token with any of the given types.

If there are no matches, return None. If there are multiple matches, return the first match.

Source code in src/robot/parsing/model/statements.py
def get_token(self, *types: str) -> 'Token|None':
    """Return a token with any of the given ``types``.

    If there are no matches, return ``None``. If there are multiple
    matches, return the first match.
    """
    for token in self.tokens:
        if token.type in types:
            return token
    return None

get_tokens

get_tokens(*types: str) -> list[Token]

Return tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_tokens(self, *types: str) -> 'list[Token]':
    """Return tokens having any of the given ``types``."""
    return [t for t in self.tokens if t.type in types]

get_value

get_value(type: str, default: str) -> str
get_value(type: str, default: None = None) -> str | None
1
2
3
get_value(
    type: str, default: str | None = None
) -> str | None

Return value of a token with the given type.

If there are no matches, return default. If there are multiple matches, return the value of the first match.

Source code in src/robot/parsing/model/statements.py
def get_value(self, type: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a token with the given ``type``.

    If there are no matches, return ``default``. If there are multiple
    matches, return the value of the first match.
    """
    token = self.get_token(type)
    return token.value if token else default

get_values

get_values(*types: str) -> tuple[str, ...]

Return values of tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_values(self, *types: str) -> 'tuple[str, ...]':
    """Return values of tokens having any of the given ``types``."""
    return tuple(t.value for t in self.tokens if t.type in types)

get_option

1
2
3
get_option(
    name: str, default: str | None = None
) -> str | None

Return value of a configuration option with the given name.

If the option has not been used, return default.

If the option has been used multiple times, values are joined together. This is typically an error situation and validated elsewhere.

New in Robot Framework 6.1.

Source code in src/robot/parsing/model/statements.py
def get_option(self, name: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a configuration option with the given ``name``.

    If the option has not been used, return ``default``.

    If the option has been used multiple times, values are joined together.
    This is typically an error situation and validated elsewhere.

    New in Robot Framework 6.1.
    """
    return self._get_options().get(name, default)

Error

Error(tokens: Sequence[Token], errors: Sequence[str] = ())

Bases: Statement

Source code in src/robot/parsing/model/statements.py
def __init__(self, tokens: 'Sequence[Token]', errors: 'Sequence[str]' = ()):
    self.tokens = tuple(tokens)
    self.errors = tuple(errors)

from_tokens classmethod

from_tokens(tokens: Sequence[Token]) -> Statement

Create a statement from given tokens.

Statement type is got automatically from token types.

This classmethod should be called from :class:Statement, not from its subclasses. If you know the subclass to use, simply create an instance of it directly.

Source code in src/robot/parsing/model/statements.py
@classmethod
def from_tokens(cls, tokens: 'Sequence[Token]') -> 'Statement':
    """Create a statement from given tokens.

    Statement type is got automatically from token types.

    This classmethod should be called from :class:`Statement`, not from
    its subclasses. If you know the subclass to use, simply create an
    instance of it directly.
    """
    handlers = cls.statement_handlers
    for token in tokens:
        if token.type in handlers:
            return handlers[token.type](tokens)
    if any(token.type == Token.ASSIGN for token in tokens):
        return KeywordCall(tokens)
    return EmptyLine(tokens)

get_token

get_token(*types: str) -> Token | None

Return a token with any of the given types.

If there are no matches, return None. If there are multiple matches, return the first match.

Source code in src/robot/parsing/model/statements.py
def get_token(self, *types: str) -> 'Token|None':
    """Return a token with any of the given ``types``.

    If there are no matches, return ``None``. If there are multiple
    matches, return the first match.
    """
    for token in self.tokens:
        if token.type in types:
            return token
    return None

get_tokens

get_tokens(*types: str) -> list[Token]

Return tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_tokens(self, *types: str) -> 'list[Token]':
    """Return tokens having any of the given ``types``."""
    return [t for t in self.tokens if t.type in types]

get_value

get_value(type: str, default: str) -> str
get_value(type: str, default: None = None) -> str | None
1
2
3
get_value(
    type: str, default: str | None = None
) -> str | None

Return value of a token with the given type.

If there are no matches, return default. If there are multiple matches, return the value of the first match.

Source code in src/robot/parsing/model/statements.py
def get_value(self, type: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a token with the given ``type``.

    If there are no matches, return ``default``. If there are multiple
    matches, return the value of the first match.
    """
    token = self.get_token(type)
    return token.value if token else default

get_values

get_values(*types: str) -> tuple[str, ...]

Return values of tokens having any of the given types.

Source code in src/robot/parsing/model/statements.py
def get_values(self, *types: str) -> 'tuple[str, ...]':
    """Return values of tokens having any of the given ``types``."""
    return tuple(t.value for t in self.tokens if t.type in types)

get_option

1
2
3
get_option(
    name: str, default: str | None = None
) -> str | None

Return value of a configuration option with the given name.

If the option has not been used, return default.

If the option has been used multiple times, values are joined together. This is typically an error situation and validated elsewhere.

New in Robot Framework 6.1.

Source code in src/robot/parsing/model/statements.py
def get_option(self, name: str, default: 'str|None' = None) -> 'str|None':
    """Return value of a configuration option with the given ``name``.

    If the option has not been used, return ``default``.

    If the option has been used multiple times, values are joined together.
    This is typically an error situation and validated elsewhere.

    New in Robot Framework 6.1.
    """
    return self._get_options().get(name, default)

errors property writable

errors: tuple[str, ...]

Errors got from the underlying ERRORtoken.

Errors can be set also explicitly. When accessing errors, they are returned along with errors got from tokens.