Skip to content

${None} converted to string even if argument default value is None #3908

Closed

Description

@pekkaklarck

If we have a keyword like

def example(arg: str = None):
    print(arg, type(arg))

and call it like

Example    ${None}

the explicitly given Python None will be converted to a string. This is a regression in RF 4.0, with earlier versions None is passed as-is. Luckily this isn't a very common situation as it's generally better to not pass an argument at all in which the argument will have the original default value.

Activity

  1. added this to the v4.0.1 milestone on Mar 26, 2021
  2. pekkaklarck commented on Mar 26, 2021

    @pekkaklarck
    MemberAuthor

    There were many changes in RF 4.0 that contributed to this regression:

    The last point may sound surprising because the example didn't use Union, but in fact Python's typing.get_type_hints that we use adds it automatically. What happens in practice is that arg: str = None is converted to arg: Optional[str] = None which in turn is just a different way to write str: Union[str, None] = None.

    The underlying bug is thus that when we have type hint like Union[str, None] and call it with a real None, we do conversion even if the type is one of the accepted types. This is exactly the same problem as the one reported by #3897. Because the manifestation of the bug is so different, I decided to submit a separate issue.

  3. pekkaklarck commented on Mar 30, 2021

    @pekkaklarck
    MemberAuthor

    This problem was fixed by PR #3895. Still need to add an explicit test for exactly this case before closing.

  4. added theissue type on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions