-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
add keyword #446
Conversation
|
||
from typing import Sequence | ||
|
||
def iskeyword(s: str) -> bool: ... |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using AnyStr
then.
According to #439, it would be better to use |
Ho, okay, using it then. |
I just found the most trivial python module.
https://docs.python.org/3/library/keyword.html