Skip to content

add keyword #446

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

Merged
merged 3 commits into from
Aug 5, 2016
Merged

add keyword #446

merged 3 commits into from
Aug 5, 2016

Conversation

tharvik
Copy link
Contributor

@tharvik tharvik commented Aug 5, 2016

I just found the most trivial python module.

https://docs.python.org/3/library/keyword.html


from typing import Sequence

def iskeyword(s: str) -> bool: ...
Copy link
Contributor

@matthiaskramm matthiaskramm Aug 5, 2016

Choose a reason for hiding this comment

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

This also works on bytes, Tuple[str], Tuple[bytes], frozenset[str], etc.

We could use something like Iterable[Union[Text, bytes]], but it also needs to be hashable.
Maybe just Union[Text, bytes] is good enough.

Copy link
Contributor Author

@tharvik tharvik Aug 5, 2016

Choose a reason for hiding this comment

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

Correct, it works on every Hashable, but I'm unable to find a concret example where it would be correct to test that a frozenset is a keyword, it would be better to trigger a warning.

In CPython implementation, the code is simply

iskeyword = frozenset(kwlist).__contains__

I don't think that was intended to handle testing other type of value, it works, but that's not the point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. But we should at least allow unicode (on Python 2) and bytes (on Python 3).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using AnyStr then.

@matthiaskramm
Copy link
Contributor

According to #439, it would be better to use Union[Text, bytes].

@tharvik
Copy link
Contributor Author

tharvik commented Aug 5, 2016

Ho, okay, using it then.

@gvanrossum gvanrossum merged commit 4fa352e into python:master Aug 5, 2016
@tharvik tharvik deleted the add_keyword branch August 8, 2016 06:47
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