Bug report
Bug description:
keyword.iskeyword() and keyword.issoftkeyword() don't accept the unhashable types list, dict and bytearray as shown below:
from keyword import iskeyword
print(iskeyword([1, 2, 3])) # TypeError: unhashable type: 'list'
print(iskeyword({'name':'John'})) # TypeError: unhashable type: 'dict'
print(iskeyword(bytearray(b'ABC'))) # TypeError: unhashable type: 'bytearray'
from keyword import issoftkeyword
print(issoftkeyword([1, 2, 3])) # TypeError: unhashable type: 'list'
print(issoftkeyword({'name':'John'})) # TypeError: unhashable type: 'dict'
print(issoftkeyword(bytearray(b'ABC'))) # TypeError: unhashable type: 'bytearray'
But keyword.iskeyword() and keyword.issoftkeyword() accept the unhashable type set as shown below:
from keyword import iskeyword
print(iskeyword({1, 2, 3}))
# False
from keyword import issoftkeyword
print(issoftkeyword({1, 2, 3}))
# False
And, keyword.iskeyword() and keyword.issoftkeyword() accept the hashable types str, bytes, tuple and frozenset as shown below:
from keyword import iskeyword
print(iskeyword('ABC'))
print(iskeyword(b'ABC'))
print(iskeyword((1, 2, 3)))
print(iskeyword(frozenset([1, 2, 3])))
# False
from keyword import issoftkeyword
print(issoftkeyword('ABC'))
print(issoftkeyword(b'ABC'))
print(issoftkeyword((1, 2, 3)))
print(issoftkeyword(frozenset([1, 2, 3])))
# False
So, keyword.iskeyword() and keyword.issoftkeyword() shouldn't accept all unhashable types including set for consistency.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Bug report
Bug description:
keyword.iskeyword() and keyword.issoftkeyword() don't accept the unhashable types
list,dictandbytearrayas shown below:But
keyword.iskeyword()andkeyword.issoftkeyword()accept the unhashable typesetas shown below:And,
keyword.iskeyword()andkeyword.issoftkeyword()accept the hashable typesstr,bytes,tupleandfrozensetas shown below:So,
keyword.iskeyword()andkeyword.issoftkeyword()shouldn't accept all unhashable types includingsetfor consistency.CPython versions tested on:
3.12
Operating systems tested on:
Windows