Skip to content

Argument conversion and validation with non-string argument values #3735

Closed

Description

@pekkaklarck

When argument conversion was added in RF 3.1 (#2890, #2947, #2932) a decision was made that conversion is done only if the given argument is a Unicode string. This approach has some limitations and a decision has been made to support conversion also with other argument types.

The problem here is that there is an unlimited amount of types users could use and handling all cases sanely is likely not easy. There are, however, many simple and useful cases like converting an integer to a float if a keyword accepts arg: float and accepting numbers with arg: timedelta.

One important decision to be made is handling types we cannot convert. For example, if we have arg: int and it is called with None, what should we do. We can either pass the given argument as-is or, probably better, make it an error. Making this an error is backwards incompatible change, though.

Activity

  1. added this to the v4.0 milestone on Oct 22, 2020
  2. pekkaklarck commented on Oct 25, 2020

    @pekkaklarck
    MemberAuthor

    Conversion logic will be changed like this:

    1. Following converters are enhanced to accept listed non-string values. Unless explicitly noted, value is converted to the expected type.

      • BooleanConverter: int, float and None are accepted and passed as-is without conversion.
      • IntegerConverter: float is accepted if no precision is lost (e.g. 1.0 is ok but 1.1 is not).
      • FloatConverter: int is accepted
      • DecimalConverter: int and float are accepted
      • DateTimeConverter: int and float are accepted and considered to be an epoch timestamp
      • TimeDeltaConverter: int and float are accepted and considered seconds
      • BytesConverter: bytearray is accepted
      • ByteArrayConverter: bytes is accepted
      • ListConverter: tuple is accepted
      • TupleConverter: list is accepted
      • SetConverter: frozenset, list, tuple and dict are accepted
      • FrozenSetConverter: set, list, tuple and dict are accepted
    2. All converters also accept values of their own type and pass them as-is.

    3. All other types are considered to be errors.

  3. pekkaklarck commented on Oct 25, 2020

    @pekkaklarck
    MemberAuthor

    This issue ought to be done except for updating the User Guide. That will be done soonish when all type conversion enhancements are done.

  4. changed the title [-]Argument conversion should work also when given argument isn't a string[/-] [+]Argument conversion and validation with non-string argument values[/+] on Oct 25, 2020
  5. added a commit that references this issue on Nov 2, 2020
    24cec81
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