code: def validate(key):
      
      if not isinstance(key, (str, bytes)):
          raise KeyError('Key must be of type str or bytes, found type {}'.format(type(key)))
docs: Check that the key is a string or bytestring.
  
      That's the only valid type of key.