-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add public argument conversion API for libraries and other tools #4942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The >>> from robot.running import TypeInfo
>>> info = TypeInfo.from_type_hint(int)
>>> info.convert('42')
42
>>> info = TypeInfo.from_type_hint('int | float')
>>> info.convert('3.14') Making this a public API basically requires the following:
We could also consider changing |
- Expose via `robot.api`. - Add docstrings. - Enhance `from_dict` now that also it is public. - Small error reporting enhancement. This is the core part of #4942.
It used to work only with `Languages` instances but it was supposed to work also with strings. To some extend related to #4942.
Add also tests for using `TypeInfo.convert` in libraries. They work also as usage examples. Part of #4942.
Changing |
Hi @pekkaklarck ,
We are using
TypeConverter
class in Robot Framework Browser in multiple places, to convert arguments of*varagrs
when calling internal keywords.Unfortunately this API is no longer be able to digest real
type
values.We need “dynamic” type conversion because of many reasons.
With dynamic i mean we do Robot type conversion inside Browser lib when Robot is not able to do.
*varags
argument that collects all old positional args and assigns them in the old order to the variables inside. Therefore there is no type hinting in the arguments. but we have a Catalog of the original types which can be used to convert.Promise To
andWait For Condition
which calls our keywords internally and has*args
to take the arguments. These two keywords iterate over the called keywords interface and try to convert the arguments according to their type. Also in this case we want/need to support dynamic argument conversion.For us it is not really important, if exactly this function
converter_for()
will stay compatible or if a new function will be implemented to get to get the proper converter for a Python type.However it would be more convenient for our users to stay compatible, so they do not necessarily need to update Browser, when updating RF.
We do currently:
A Public API for this would be nice too.
Or maybe even just a convenient function for Converting value to type as a static method.
Something like
TypeConverters.convert_to_type(name: str, value: Any, destination_type: type)
Cheers
The text was updated successfully, but these errors were encountered: