Skip to content

Support custom converters for user keyword argument type hints #5783

Open

Description

@gohierf

Context

User keyword [Arguments] type hints (${name: type}, added in RF 7.0)
currently only accept Python built-ins and a small standard-library set.
Per the
User Guide, "Variable type conversion":

"The biggest limitations compared to the argument conversion with
library keywords is that Enum and TypedDict conversions are not
supported and that custom converters cannot be used. These limitations
may be lifted in the future versions."

In practice, a hint like ${point: Point} (a custom class with a
registered converter, e.g. Point.from_string) fails at parse time with
Unrecognized type 'Point', even when Point is registered as a
converter on an imported library. Library keywords get full custom-type
auto-conversion (#4088); user keywords cannot use the same converters at
all today.

Request

Allow user keyword type hints to resolve custom types the same way library
keyword arguments do, either via converters registered on an imported
library, or via whatever mechanism comes out of #4944 (global scope type
converters). This would make user keywords and library keywords behave
consistently for the same custom type, closing a gap that currently forces
a manual workaround anywhere a user keyword needs a typed argument.

Related

  • Ability to register custom converters for keyword arguments #4088, "Ability to register custom converters for keyword arguments"
    (closed, implemented): the library-keyword side of custom converters
    that this issue would extend to user keywords.
  • Support global scope type converters #4944, "Support global scope type converters" (open): a global converter
    registry would likely be the natural mechanism to also unlock this for
    user keywords, but that issue doesn't explicitly call out user keyword
    type hints as a target, hence this separate, more specific request.

Activity

  1. pekkaklarck commented on Sep 12, 2026

    @pekkaklarck
    Member

    The first step with getting this done is deciding how/where to register custom converters. Alternatives:

    1. If we add support for global converters (Support global scope type converters #4944), they should work also with user keywords, but making all user keyword converters global doesn't sound good to me.
    2. Dedicated setting like Converters that loads converters that are implemented the same way as with libraries. Would work, but custom converters feel like a too narrow usage for a new setting.
    3. Reuse converters that imported libraries have registered.

    The last alternative feels best to be, but it has its drawbacks as well. Most importantly, using converters from all imported libraries could result in a situation where conversion happens when it shouldn't. This is especially a problem, because Robot's keyword namespaces are a mess (#2581) and currently a resource file sees all libraries imported within a test suite, not only libraries imported in the resource file itself. I see at least the following solutions:

    1. Search converters only from libraries the resource file has imported itself. This has a problem that a resource file may have imported another resource file that imports the libraries that the original resource file uses, and it such cases it would be natural if also converters registered by those libraries were available. We could try to track import chains, but that gets complicated and it's probably better to wait until Robot's namespaces are fixed.
    2. Make it somehow possible for libraries to opt-out from exposing their converters. Perhaps the converter dictionary could have a key like "global": False or "expose": False when you don't want converters to be exposed to user keywords. This could also be opt-in like "global": True, but I believe you'd in general want to allow user keyword to use these converters.
    3. Do nothing. Conflicts with converters would likely be rare in general and even rarer if we get keyword namespaces fixed. Opt-out system can be implemented later if actually needed.

    I got a feeling that "do nothing" would be fine, especially if keyword namespaces are fixed, but implementing the opt-out functionality would likely be easy as well.

    If we decide to use converters registered by libraries, it is possible then to create a library that only has converters for user keywords. In such case we shouldn't log a warning that a library contains no keywords.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions