class_docstr: A set-like where the `pop` method returns the smallest item, as sorted by an
  arbitrary key function. Ties are broken by oldest first.
  
  Values must be compatible with :mod:`weakref`.
  
  Parameters
  ----------
  key: Callable
      A function that takes a single element of the collection as a parameter and
      returns a sorting key. The key does not need to be hashable and does not need to
      support :mod:`weakref`.
  
  Note
  ----
  The key returned for each element should not to change over time. If it does, the
  position in the heap won't change, even if the element is re-added, and it *may* not
  change even if it's discarded and then re-added later.
class_docstr_tok: ["A","set-like","where","the","`","pop","`","method","returns","the","smallest","item",",","as","sorted","by","an","arbitrary","key","function",".","Ties","are","broken","by","oldest","first",".","Values","must","be","compatible","with",":","mod",":","`","weakref","`",".","Parameters","--","--","--","--","--","key",":","Callable","A","function","that","takes","a","single","element","of","the","collection","as","a","parameter","and","returns","a","sorting","key",".","The","key","does","not","need","to","be","hashable","and","does","not","need","to","support",":","mod",":","`","weakref","`",".","Note","--","--","The","key","returned","for","each","element","should","not","to","change","over","time",".","If","it","does",",","the","position","in","the","heap","wo","n't","change",",","even","if","the","element","is","re-added",",","and","it","*","may","*","not","change","even","if","it","'s","discarded","and","then","re-added","later","."]
docstr: Return the smallest element without removing it
docstr_tok: ["Return","the","smallest","element","without","removing","it"]
code: def peek(self) -> T:
      """Return the smallest element without removing it"""
      if not self._data:
          raise KeyError("peek into empty set")
      while True:
          value = self._heap[0][2]()
          if value in self._data:
              return value
          heapq.heappop(self._heap)
          self._sorted = False
  
imports: from __future__ import annotations
  import heapq
  import itertools
  import weakref
  from collections import OrderedDict, UserDict
  from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, MutableSet
  from typing import Any, TypeVar, cast
label_desc: Use image node_id 9 for calling the HeapSet obj's underlying member method code with example usage: obj.peek() and returns: value