Reputation: 170638
It seems that six library does not have a tuple type definition and I am currently looking to write the code below in a way that works with both Python 2 and Python 3.
return (type(key) in (types.TupleType, types.ListType)
PS. Don't blame me for that line, I only try to port it, is not written by me ;)
Upvotes: 0
Views: 817
Reputation: 375844
The best way would be:
return isinstance(key, (tuple, list))
This is simple, direct, clear, works in both 2.x and 3.x, and properly handles subclasses.
Upvotes: 4