Skip to content

Convert and validate TypedDict items #4477

Closed
Closed

Description

@pekkaklarck

Currently when using TypedDict as a type hint, Robot simply converts the value to a dictionary but doesn't convert or validated individual items. We are planning to add conversion and validation for generics in RF 5.1 (#4433) and it would be both convenient and consistent to also handle TypedDict objects better.

This change will cause backwards incompatibility problems if someone has used TypedDict as a type hint and used arguments do not actually match it. I don't think that's a desired situation and explicitly preventing it can be considered a bug fix.

Activity

  1. added this to the v5.1 milestone on Sep 25, 2022
  2. pekkaklarck commented on Sep 25, 2022

    @pekkaklarck
    MemberAuthor

    This is pretty easy to implement, I got a prototype ready but it needs adequate tests, and I hope we can still squeeze this into RF 5.1. To avoid conflicts, it probably is a good idea to get #4433 done first.

  3. pekkaklarck commented on Sep 29, 2022

    @pekkaklarck
    MemberAuthor

    It turned out that the Browser library, probably the biggest user of TypedDicts with Robot, has internally handled TypedDicts so that keys are case-insensitive. That means that if you have a TypedDict like

    class Size(TypedDict):
        width: int
        height: int

    it has been possible to use it like {'WIDTH: 1600, 'HEIGHT': 900}.

    The current TypedDict conversion logic on Robot side doesn't support case-insensitive keys, so the above example won't work anymore. Browser library developers didn't consider this to be an important feature and we agreed Robot being more strict is fine. The change will, however, affect Browser users that have used this functionality on purpose or accidentally. If there turn out to be lot of users who are affected, or users have good uses cases for case-insensitivity, we can consider changing Robot's behavior later.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions