Skip to content

Type converter to Robot data - #5379

Merged
pekkaklarck merged 1 commit into
robotframework:masterfrom
aaltat:variable_types
Apr 25, 2025
Merged

pekkaklarck merged 1 commit into
robotframework:masterfrom
aaltat:variable_types

Conversation

@aaltat

@aaltat aaltat commented Mar 21, 2025

Copy link
Copy Markdown
Contributor

Fixes #3278

@aaltat
aaltat force-pushed the variable_types branch 5 times, most recently from 6640d13 to 12f11b5 Compare March 28, 2025 20:06
@aaltat
aaltat force-pushed the variable_types branch 6 times, most recently from 0eaffd2 to a90ad3d Compare April 4, 2025 14:07
@aaltat
aaltat force-pushed the variable_types branch 2 times, most recently from b78e5b4 to 295d919 Compare April 7, 2025 11:54
@aaltat
aaltat force-pushed the variable_types branch 16 times, most recently from 0e7e8c3 to b213b70 Compare April 13, 2025 20:00
@aaltat
aaltat force-pushed the variable_types branch 7 times, most recently from 368268a to c06f6f9 Compare April 16, 2025 14:44
@aaltat
aaltat marked this pull request as ready for review April 16, 2025 14:47

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good in general, but there seems to be a bug in handling embedded arguments. There are few things to fine-tune as well and TypeInfo.from_variable should get documentation.

Comment thread src/robot/running/arguments/embedded.py Resolved
Comment thread src/robot/running/arguments/embedded.py Resolved
Comment thread src/robot/running/arguments/embedded.py Resolved
Comment thread src/robot/running/arguments/embedded.py Resolved
Comment thread src/robot/running/arguments/typeinfo.py Resolved
Comment thread src/robot/running/arguments/typeinfo.py Resolved
Comment thread src/robot/variables/assigner.py Resolved
@aaltat
aaltat force-pushed the variable_types branch 2 times, most recently from 92d074e to 1261e8a Compare April 25, 2025 19:32
@aaltat
aaltat requested a review from pekkaklarck April 25, 2025 19:35

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! There are few things still to be enhanced, see the inline comments for details, but I can take care of them.

Embedded type with custom regular expression 111
VAR ${x} 1
VAR ${y} 2
Embedded ${x} and ${y}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Embedded args with variables would deserve its own test. More importantly, variable that's not a string should be tested.

from pathlib import Path
from typing import Any, ForwardRef, get_args, get_origin, get_type_hints, Literal, Union

from robot.variables.search import VariableMatch, search_variable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be imported from robot.variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned out VariableMatch wasn't exposed via robot.variables. It should be.

for nested in info.nested:
cls._validate_var_type(nested)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line.


def _split_assignment(self, assignment, handle_list_and_dict=True):
match: VariableMatch = search_variable(assignment, parse_type=True)
from robot.running import TypeInfo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Import within a method should be on the first line.
  • match shouldn't need a type hint because search_variable has a return type.


def _convert(self, value, type_):
from robot.running import TypeInfo
info = TypeInfo.from_type_hint(type_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using TypeInfo.from_variable would avoid the need to handle @ and & variables in ListVariableResolver and DictVariableResolver, but because we already have a type here, and needed to construct a variable, that might be more complicated anyway.

@classmethod
def from_variable(cls, variable: 'str|VariableMatch',
handle_list_and_dict: bool = True) -> 'TypeInfo|None':
"""Construct a ``TypeInfo`` based on a variable."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here could be an example about the variable syntax and should be a note about this being new in RF 7.3.

@pekkaklarck
pekkaklarck merged commit 3a57fd1 into robotframework:master Apr 25, 2025
@aaltat
aaltat deleted the variable_types branch April 25, 2025 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variable type conversion

2 participants