You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
${None} converted to string even if argument default value is None #3908
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.
Union conversion (Support type conversion with multiple possible types #3738) was implemented so that arguments are always converted, even if they would have one of the accepted types, and conversion is attempted in the order types are listed in the Union.
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.
Activity
pekkaklarck commentedon Mar 26, 2021
There were many changes in RF 4.0 that contributed to this regression:
Unionconversion (Support type conversion with multiple possible types #3738) was implemented so that arguments are always converted, even if they would have one of the accepted types, and conversion is attempted in the order types are listed in theUnion.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 thatarg: str = Noneis converted toarg: Optional[str] = Nonewhich in turn is just a different way to writestr: Union[str, None] = None.The underlying bug is thus that when we have type hint like
Union[str, None]and call it with a realNone, 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.Unionon conversion: Don't convert value if it is already a valid type. (
pekkaklarck commentedon Mar 30, 2021
This problem was fixed by PR #3895. Still need to add an explicit test for exactly this case before closing.
Explicit test for type conversion with `a: str = None`.