Skip to content

param:Optional[x] = None type hint behaves differently than Robot Framework #64

@mkorpela

Description

@mkorpela

Please add the following "hacky" Optional removal to

return hints

 def _remove_optional_none_type_hints(self, type_hints, defaults):
    # If argument has None as a default, typing.get_type_hints adds
    # optional None to the information it returns. We don't want that.
    for arg in defaults:
        if defaults[arg] is None and arg in type_hints:
            type_ = type_hints[arg]
            if self._is_union(type_):
                try:
                    types = type_.__args__
                except AttributeError:
                    # Python 3.5.2's typing uses __union_params__ instead
                    # of __args__. This block can likely be safely removed
                    # when Python 3.5 support is dropped
                    types = type_.__union_params__
                if len(types) == 2 and types[1] is type(None):
                    type_hints[arg] = types[0]

https://github.com/robotframework/robotframework/blob/5dc9affd4aee31703a58ad105ed49579b1ca7067/src/robot/running/arguments/argumentparser.py#L101

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions