code: def _to_dict(self):
          
          if self.all_:
              return {"all": True}
  
          return {
              "keys": self.keys,
              "ranges": [keyrange._to_dict() for keyrange in self.ranges],
          }
docs: Return keyset's state as a dict.
  
          The result can be used to serialize the instance and reconstitute
          it later using :meth:`_from_dict`.
  
          :rtype: dict
          :returns: state of this instance.