@@ -1541,7 +1541,8 @@ Specifying multiple possible types
1541
1541
Starting from Robot Framework 4.0, it is possible to specify that an argument
1542
1542
has multiple possible types. In this situation argument conversion is attempted
1543
1543
based on each type in the order they have been specified. If any conversion
1544
- succeeds, the resulting value is used, and otherwise the whole conversion fails.
1544
+ succeeds, the resulting value is used without attempting conversion to remaining
1545
+ types. If no type conversion succeeds, the whole conversion fails.
1545
1546
1546
1547
When using function annotations, the natural syntax to specify that argument
1547
1548
has multiple possible types is using Union _:
@@ -1556,7 +1557,7 @@ has multiple possible types is using Union_:
1556
1557
1557
1558
An alternative is giving types a tuple. It is not recommended with annotations
1558
1559
because that syntax is not supported by other tools, but it works well with
1559
- the `@keyword ` decorator:
1560
+ the `@keyword ` decorator and is Python 2 compatible :
1560
1561
1561
1562
.. sourcecode :: python
1562
1563
@@ -1571,6 +1572,12 @@ With the above examples the `length` argument would first be converted to an
1571
1572
integer and if that fails then to a float. The `padding ` would be first
1572
1573
converted to `None `, then to an integer, and finally to a string.
1573
1574
1575
+ Because conversion is attempted one-by-one and string conversion always succeeds,
1576
+ possible `str ` should be the last type. For example, using `Union[str, int] ` would
1577
+ cause all arguments, including integers, to be converted to strings, but
1578
+ `Union[int, str] ` means that integer conversion is attempted first and string
1579
+ conversion is done only if that fails.
1580
+
1574
1581
If any of the specified types is not recognized by Robot Framework and
1575
1582
the given argument cannot be converted to any of the types before it,
1576
1583
the given argument will be used as-is. For example, with this keyword
0 commit comments