robot.running.arguments.typeinfo
¶
TypeInfo
¶
Represents an argument type.
Normally created using the :meth:from_type_hint
classmethod.
With unions and parametrized types, :attr:nested
contains nested types.
Values can be converted according to this type info by using the
:meth:convert
method.
Part of the public API starting from Robot Framework 7.0. In such usage
should be imported via the :mod:robot.api
package.
Source code in src/robot/running/arguments/typeinfo.py
nested
¶
Nested types as a tuple of TypeInfo
objects.
Used with parameterized types and unions.
Source code in src/robot/running/arguments/typeinfo.py
from_type_hint
classmethod
¶
Construct a TypeInfo
based on a type hint.
The type hint can be in various different formats:
- an actual type such as
int
- a parameterized type such as
list[int]
- a union such as
int | float
- a string such as
'int'
,'list[int]'
or'int | float'
- a
TypedDict
(represented as a :class:TypedDictInfo
) - a sequence of supported type hints to create a union from such as
[int, float]
or('int', 'list[int]')
In special cases using a more specialized method like :meth:from_sequence
may be more appropriate than using this generic method.
Source code in src/robot/running/arguments/typeinfo.py
from_type
classmethod
¶
Construct a TypeInfo
based on an actual type.
Use :meth:from_type_hint
if the type hint can also be something else
than a concrete type such as a string.
Source code in src/robot/running/arguments/typeinfo.py
from_string
classmethod
¶
Construct a TypeInfo
based on a string.
In addition to just types names or their aliases like int
or integer
,
supports also parameterized types like list[int]
as well as unions like
int | float
.
Use :meth:from_type_hint
if the type hint can also be something else
than a string such as an actual type.
Source code in src/robot/running/arguments/typeinfo.py
from_sequence
classmethod
¶
Construct a TypeInfo
based on a sequence of types.
Types can be actual types, strings, or anything else accepted by
:meth:from_type_hint
. If the sequence contains just one type,
a TypeInfo
created based on it is returned. If there are more
types, the returned TypeInfo
represents a union. Using an empty
sequence is an error.
Use :meth:from_type_hint
if other types than sequences need to
supported.
Source code in src/robot/running/arguments/typeinfo.py
convert
¶
Convert value
based on type information this TypeInfo
contains.
:param value: Value to convert.
:param name: Name of the argument or other thing to convert.
Used only for error reporting.
:param custom_converters: Custom argument converters.
:param languages: Language configuration. During execution, uses the
current language configuration by default.
:param kind: Type of the thing to be converted.
Used only for error reporting.
:raises: TypeError
if there is no converter for this type or
ValueError
is conversion fails.
:return: Converted value.
Source code in src/robot/running/arguments/typeinfo.py
TypedDictInfo
¶
Bases: TypeInfo
Represents TypedDict
used as an argument.
Source code in src/robot/running/arguments/typeinfo.py
nested
¶
Nested types as a tuple of TypeInfo
objects.
Used with parameterized types and unions.
Source code in src/robot/running/arguments/typeinfo.py
from_type_hint
classmethod
¶
Construct a TypeInfo
based on a type hint.
The type hint can be in various different formats:
- an actual type such as
int
- a parameterized type such as
list[int]
- a union such as
int | float
- a string such as
'int'
,'list[int]'
or'int | float'
- a
TypedDict
(represented as a :class:TypedDictInfo
) - a sequence of supported type hints to create a union from such as
[int, float]
or('int', 'list[int]')
In special cases using a more specialized method like :meth:from_sequence
may be more appropriate than using this generic method.
Source code in src/robot/running/arguments/typeinfo.py
from_type
classmethod
¶
Construct a TypeInfo
based on an actual type.
Use :meth:from_type_hint
if the type hint can also be something else
than a concrete type such as a string.
Source code in src/robot/running/arguments/typeinfo.py
from_string
classmethod
¶
Construct a TypeInfo
based on a string.
In addition to just types names or their aliases like int
or integer
,
supports also parameterized types like list[int]
as well as unions like
int | float
.
Use :meth:from_type_hint
if the type hint can also be something else
than a string such as an actual type.
Source code in src/robot/running/arguments/typeinfo.py
from_sequence
classmethod
¶
Construct a TypeInfo
based on a sequence of types.
Types can be actual types, strings, or anything else accepted by
:meth:from_type_hint
. If the sequence contains just one type,
a TypeInfo
created based on it is returned. If there are more
types, the returned TypeInfo
represents a union. Using an empty
sequence is an error.
Use :meth:from_type_hint
if other types than sequences need to
supported.
Source code in src/robot/running/arguments/typeinfo.py
convert
¶
Convert value
based on type information this TypeInfo
contains.
:param value: Value to convert.
:param name: Name of the argument or other thing to convert.
Used only for error reporting.
:param custom_converters: Custom argument converters.
:param languages: Language configuration. During execution, uses the
current language configuration by default.
:param kind: Type of the thing to be converted.
Used only for error reporting.
:raises: TypeError
if there is no converter for this type or
ValueError
is conversion fails.
:return: Converted value.