robotcode icon indicating copy to clipboard operation
robotcode copied to clipboard

[ENHANCEMENT] Option for variable type checking

Open ggeaymond opened this issue 7 months ago • 1 comments

Problem: RobotFramework is very lenient on variable types, so to minimize errors while writing test cases I use a lot of strict typing in my python libraries, be it built in types or custom enum classes. The issue is that the RobotFramework layer will not spot if I use a wrong type, even though I explicitly specified it in the keyword definition. See the following example:

keywords.py

class keywords:
    def my_python_keyword(myvariable: int):
        print(myVariable)

testSuite.robot

*** Settings ***
Library    keywords.py

*** Variables ***
${intVar}    8
${strVar}   hello world!

*** Test Cases ***
Use My Custom Keywords
    My Keyword    ${intVar}
    My Python Keyword    ${intVar}
    My Keyword    ${strVar}
    My Python Keyword    ${strVar}

*** Keywords ***
My Keyword
    [Arguments]    ${myVariable: int}
    Log    ${myVariable}

Nothing will be spotted until runtime, where a ValueError would be raised for the last two keyword calls. Moreover, declaring a variable with ${var: int} hello isn't picked up either, until an error is raised at runtime to say that 'var' could not be set.

Requested Enhancement: Adding type checking as an option for RobotCode would help make test case writing more ergonomic and speed up debugging phases.

As an additional note, this suggestion can probably be linked to suggestion #436 about auto-completion for variables in python variable files.

ggeaymond avatar Jul 29 '25 14:07 ggeaymond