Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type hints #1666

Merged
merged 2 commits into from
Oct 1, 2020
Merged

Improve type hints #1666

merged 2 commits into from
Oct 1, 2020

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
@@ -52,7 +53,7 @@ def alert_should_be_present(
self,
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

@@ -76,7 +78,7 @@ def alert_should_be_present(

@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