Skip to content

Conversation

@aaltat
Copy link
Contributor

@aaltat aaltat commented Oct 1, 2020

No description provided.

@aaltat aaltat merged commit 594fdfc into robotframework:master Oct 1, 2020
@aaltat aaltat deleted the improve_type_hints branch October 1, 2020 20:47
text: str = "",
action: str = ACCEPT,
timeout: Union[float, str, None] = None,
timeout: Optional[timedelta] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional[] is unnecessary when there's None as a default value. Even MyPy doesn't need it unless you run it with --no-implicit-optional:
https://mypy.readthedocs.io/en/stable/command_line.html?highlight=optional#cmdoption-mypy-no-implicit-optional

Copy link
Member

@mkorpela mkorpela Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Optional is best practice if None is used. Types should not contain None as part of the type and if they do, then that should explicitly be stated.
See for example https://en.wikipedia.org/wiki/Void_safety for more details on this subject.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the default is also changing in mypy python/mypy#9091

@keyword
def alert_should_not_be_present(
self, action: str = ACCEPT, timeout: Union[float, str, None] = 0
self, action: str = ACCEPT, timeout: Union[timedelta] = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong because an argument with type timedelta cannot really have an integer as a default. You probably also meant Optional[timedelta] not Union[timedelta] (but I'd leave Optional[] away as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, what would be suitable default? The easiest would be to change it to None but that would be somewhat backwards incompatible (Because it would default to library default timeout.) Would:

def alert_should_not_be_present(self, action: str = ACCEPT, timeout = timedelta(seconds=0);

be better?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants