class_docstr: A hasher that can hash objects with cycles.
class_docstr_tok: ["A","hasher","that","can","hash","objects","with","cycles","."]
docstr: Add memoization to _to_bytes and protect against cycles in data structures.
docstr_tok: ["Add","memoization","to","_to_bytes","and","protect","against","cycles","in","data","structures","."]
code: def to_bytes(self, obj: Any) -> bytes:
      """Add memoization to _to_bytes and protect against cycles in data structures."""
      tname = type(obj).__qualname__.encode()
      key = (tname, _key(obj))
  
      # Memoize if possible.
      if key[1] is not NoResult:
          if key in self._hashes:
              return self._hashes[key]
  
      # Break recursive cycles.
      if obj in hash_stacks.current:
          return _CYCLE_PLACEHOLDER
  
      hash_stacks.current.push(obj)
  
      try:
          # Hash the input
          b = b"%s:%s" % (tname, self._to_bytes(obj))
  
          # Hmmm... It's possible that the size calculation is wrong. When we
          # call to_bytes inside _to_bytes things get double-counted.
          self.size += sys.getsizeof(b)
  
          if key[1] is not NoResult:
              self._hashes[key] = b
  
      finally:
          # In case an UnhashableTypeError (or other) error is thrown, clean up the
          # stack so we don't get false positives in future hashing calls
          hash_stacks.current.pop()
  
      return b
  
imports: import collections
  import dataclasses
  import datetime
  import functools
  import hashlib
  import inspect
  import io
  import os
  import pickle
  import struct
  import sys
  import tempfile
  import threading
  import unittest.mock
  import uuid
  import weakref
  from enum import Enum
  from typing import Any, Callable, Dict, List, Optional, Pattern, Type, Union
  from streamlit import type_util, util
  from streamlit.errors import StreamlitAPIException
  from streamlit.runtime.caching.cache_errors import UnhashableTypeError
  from streamlit.runtime.caching.cache_type import CacheType
  from streamlit.runtime.uploaded_file_manager import UploadedFile
  from streamlit.util import HASHLIB_KWARGS
label_desc: Use image node_id 3 for calling the _CacheFuncHasher obj's underlying member method code with example usage: obj.to_bytes(obj) and returns: b, _CYCLE_PLACEHOLDER, self