Repository navigation
How to inject Custom Type Hints & Custom Type Converters? #645
|
Hi there! Do we have a guide on how to teach robotframework & robotcode new types? Is it even possible? I could be wrong in a terminology. So, to better understand me, here is a case: *** Keywords ***
Do Something Cool
[Arguments] ${value: MyCustomType}
No OperationLine 3 raises an error: Just in case, my versions: I assume it's possible, but unfortunately I haven't found any clear guide on how to make it work, except of AI suggestions that actually did not work for me😅 @d-biehl highly appreciate your tips. |
Replies: 2 comments
|
this is a question you have to ask directly to the robot framework developers, but as I know this is not supported in robot framework at the moment. |
|
@d-biehl is right that Robot Framework doesn't support this yet. Here's where that's documented, where it's being tracked, and what works today. Why it fails: for The request is tracked in robotframework#5783 (open). The broader #4944 (global type converters) is on the 7.6 milestone, so a 👍 or your use case there helps. Workarounds on 7.4.1:
# MyLibrary.py
class MyCustomType:
def __init__(self, raw: str):
self.raw = raw
def parse_my_type(value: str) -> MyCustomType:
return MyCustomType(value)
ROBOT_LIBRARY_CONVERTERS = {MyCustomType: parse_my_type}
def do_something_cool(value: MyCustomType):
...
Do Something Cool
[Arguments] ${value}
VAR ${obj} ${{ mymodule.MyCustomType($value) }}
|
@d-biehl is right that Robot Framework doesn't support this yet. Here's where that's documented, where it's being tracked, and what works today.
Why it fails: for
${x: Type}(user keyword[Arguments],VAR,FOR, assignments), RF looks the name up in a fixed table of built-in types (str,int,list,Literal,Any, ...) and raisesUnrecognized typefor anything else (typeinfo.pytable, check). LibraryROBOT_LIBRARY_CONVERTERSaren't consulted there. The User Guide states that custom converters cannot be used with variable type conversion, and user keyword arguments follow the same rules. RobotCode just shows RF's own error.The request is tracked in robotframework#5783 (open). The broader #4944 …