diff --git a/atest/robot/variables/variable_types.robot b/atest/robot/variables/variable_types.robot index 11431066102..f92d9c94b2e 100644 --- a/atest/robot/variables/variable_types.robot +++ b/atest/robot/variables/variable_types.robot @@ -18,39 +18,39 @@ Variable section: With invalid values or types Variable section: Invalid syntax Error In File ... 3 variables/variable_types.robot - ... 17 Setting variable '\${BAD_TYPE: hahaa}' failed: Unrecognized type 'hahaa'. + ... 18 Setting variable '\${BAD_TYPE: hahaa}' failed: Unrecognized type 'hahaa'. Error In File - ... 4 variables/variable_types.robot 19 + ... 4 variables/variable_types.robot 20 ... Setting variable '\@{BAD_LIST_TYPE: xxxxx}' failed: Unrecognized type 'xxxxx'. Error In File - ... 5 variables/variable_types.robot 21 + ... 5 variables/variable_types.robot 22 ... Setting variable '\&{BAD_DICT_TYPE: aa=bb}' failed: Unrecognized type 'aa'. Error In File - ... 6 variables/variable_types.robot 22 + ... 6 variables/variable_types.robot 23 ... Setting variable '\&{INVALID_DICT_TYPE1: int=list[int}' failed: ... Parsing type 'dict[int, list[int]' failed: ... Error at end: Closing ']' missing. ... pattern=False Error In File - ... 7 variables/variable_types.robot 23 + ... 7 variables/variable_types.robot 24 ... Setting variable '\&{INVALID_DICT_TYPE2: int=listint]}' failed: ... Parsing type 'dict[int, listint]]' failed: ... Error at index 18: Extra content after 'dict[int, listint]'. ... pattern=False Error In File - ... 8 variables/variable_types.robot 20 + ... 9 variables/variable_types.robot 21 ... Setting variable '\&{BAD_DICT_VALUE: str=int}' failed: ... Value '{'x': 'a', 'y': 'b'}' (DotDict) cannot be converted to dict[str, int]: ... Item 'x' got value 'a' that cannot be converted to integer. ... pattern=False Error In File - ... 9 variables/variable_types.robot 18 + ... 10 variables/variable_types.robot 19 ... Setting variable '\@{BAD_LIST_VALUE: int}' failed: ... Value '['1', 'hahaa']' (list) cannot be converted to list[int]: ... Item '1' got value 'hahaa' that cannot be converted to integer. ... pattern=False Error In File - ... 10 variables/variable_types.robot 16 + ... 11 variables/variable_types.robot 17 ... Setting variable '\${BAD_VALUE: int}' failed: Value 'not int' cannot be converted to integer. ... pattern=False @@ -75,7 +75,7 @@ VAR syntax: Type can not be set as variable VAR syntax: Type syntax is not resolved from variable Check Test Case ${TESTNAME} -Vvariable assignment +Variable assignment Check Test Case ${TESTNAME} Variable assignment: List @@ -99,6 +99,9 @@ Variable assignment: Invalid type for list Variable assignment: Invalid variable type for dictionary Check Test Case ${TESTNAME} +Variable assignment: No type when using variable + Check Test Case ${TESTNAME} + Variable assignment: Multiple Check Test Case ${TESTNAME} @@ -136,7 +139,7 @@ User keyword: Invalid value User keyword: Invalid type Check Test Case ${TESTNAME} Error In File - ... 0 variables/variable_types.robot 333 + ... 0 variables/variable_types.robot 355 ... Creating keyword 'Bad type' failed: ... Invalid argument specification: Invalid argument '\${arg: bad}': ... Unrecognized type 'bad'. @@ -144,7 +147,7 @@ User keyword: Invalid type User keyword: Invalid assignment with kwargs k_type=v_type declaration Check Test Case ${TESTNAME} Error In File - ... 1 variables/variable_types.robot 337 + ... 1 variables/variable_types.robot 359 ... Creating keyword 'Kwargs does not support key=value type syntax' failed: ... Invalid argument specification: Invalid argument '\&{kwargs: int=float}': ... Unrecognized type 'int=float'. @@ -155,6 +158,17 @@ Embedded arguments Embedded arguments: With variables Check Test Case ${TESTNAME} +Embedded arguments: Invalid type in library + Check Test Case ${TESTNAME} + Error in library + ... Embedded + ... Adding keyword 'bad_type' failed: + ... Invalid embedded argument '\${value: bad}': Unrecognized type 'bad'. + ... index=8 + +Embedded arguments: Type only in embedded + Check Test Case ${TESTNAME} + Embedded arguments: Invalid value Check Test Case ${TESTNAME} @@ -164,7 +178,7 @@ Embedded arguments: Invalid value from variable Embedded arguments: Invalid type Check Test Case ${TESTNAME} Error In File - ... 2 variables/variable_types.robot 357 + ... 2 variables/variable_types.robot 379 ... Creating keyword 'Embedded invalid type \${x: invalid}' failed: ... Invalid embedded argument '\${x: invalid}': ... Unrecognized type 'invalid'. diff --git a/atest/testdata/test_libraries/Embedded.py b/atest/testdata/test_libraries/Embedded.py index 2b9230c31c4..249c992368f 100644 --- a/atest/testdata/test_libraries/Embedded.py +++ b/atest/testdata/test_libraries/Embedded.py @@ -13,3 +13,11 @@ def called_times(self, times): raise AssertionError( f"Called {self.called} time(s), expected {times} time(s)." ) + + @keyword("Embedded invalid type in library ${value: bad}") + def bad_type(self, value: str): + return value + + @keyword("Type only in embedded ${value: int}") + def no_type(self, value): + return value diff --git a/atest/testdata/variables/variable_types.robot b/atest/testdata/variables/variable_types.robot index c6ccd22cef6..c4d142abe13 100644 --- a/atest/testdata/variables/variable_types.robot +++ b/atest/testdata/variables/variable_types.robot @@ -1,4 +1,5 @@ *** Settings *** +Library ../test_libraries/Embedded.py Variables extended_variables.py @@ -75,6 +76,9 @@ VAR syntax Should be equal ${x} 123 type=int VAR ${x: int} 1 2 3 separator= Should be equal ${x} 123 type=int + VAR ${name} x + VAR ${${name}: int} 432 + Should be equal ${x} 432 type=int VAR syntax: List VAR ${x: list} [1, "2", 3] @@ -89,6 +93,8 @@ VAR syntax: Dictionary Should be equal ${x} {"1": 2, "3": 4} type=dict VAR &{x: int=str} 3=4 5=6 Should be equal ${x} {3: "4", 5: "6"} type=dict + VAR &{x: int = str} 100=200 300=400 + Should be equal ${x} {100: "200", 300: "400"} type=dict VAR &{x: int=dict[str, float]} 30={"key": 1} 40={"key": 2.3} Should be equal ${x} {30: {"key": 1.0}, 40: {"key": 2.3}} type=dict @@ -115,7 +121,7 @@ VAR syntax: Type syntax is not resolved from variable VAR ${${type}} 4242 Should be equal ${tidii: int} 4242 type=str -Vvariable assignment +Variable assignment ${x: int} = Set Variable 42 Should be equal ${x} 42 type=int @@ -162,6 +168,13 @@ Variable assignment: Invalid variable type for dictionary [Documentation] FAIL Unrecognized type 'int=str'. ${x: int=str} = Create dictionary 1=2 3=4 +Variable assignment: No type when using variable + [Documentation] FAIL + ... Resolving variable '\${x: str}' failed: SyntaxError: invalid syntax (, line 1) + ${x: date} Set Variable 2025-04-30 + Should be equal ${x} 2025-04-30 type=date + Should be equal ${x: str} 2025-04-30 type=str + Variable assignment: Multiple ${a: int} ${b: float} = Create List 1 2.3 Should be equal ${a} 1 type=int @@ -258,7 +271,6 @@ User keyword: Invalid assignment with kwargs k_type=v_type declaration Kwargs does not support key=value type syntax Embedded arguments - [Tags] kala Embedded 1 and 2 Embedded type 1 and no type 2 Embedded type with custom regular expression 111 @@ -268,6 +280,16 @@ Embedded arguments: With variables VAR ${y} ${2.0} Embedded ${x} and ${y} +Embedded arguments: Invalid type in library + [Documentation] FAIL No keyword with name 'Embedded Invalid type in library 111' found. + Embedded Invalid type in library 111 + +Embedded arguments: Type only in embedded + [Documentation] FAIL + ... Embedded arguments do not support type information with library keywords: \ + ... 'Embedded.Type only in embedded \${value: int}'. Use normal type hints instead. + Type only in embedded 987 + Embedded arguments: Invalid value [Documentation] FAIL ValueError: Argument 'kala' cannot be converted to integer. Embedded 1 and kala diff --git a/src/robot/running/librarykeywordrunner.py b/src/robot/running/librarykeywordrunner.py index 44fd64194a5..d0562340a17 100644 --- a/src/robot/running/librarykeywordrunner.py +++ b/src/robot/running/librarykeywordrunner.py @@ -185,6 +185,12 @@ class EmbeddedArgumentsRunner(LibraryKeywordRunner): def __init__(self, keyword: "LibraryKeyword", name: "str"): super().__init__(keyword, name) + if any(keyword.embedded.types): + raise DataError( + "Embedded arguments do not support type information " + f"with library keywords: '{keyword.full_name}'. " + "Use normal type hints instead." + ) self.embedded_args = keyword.embedded.parse_args(name) def _resolve_arguments(