code: def test_weakref_err(create_weakref, has_callback):
      class C:
          __slots__ = []
  
      def callback(_):
          pass
  
      ob = C()
      # Should raise TypeError on CPython
      with pytest.raises(
          TypeError
      ) if not env.PYPY else contextlib.nullcontext():
          if has_callback:
              _ = create_weakref(ob, callback)
          else:
              _ = create_weakref(ob)
  
imports: import contextlib
  import sys
  import types
  import pytest
  import env
  from pybind11_tests import detailed_error_messages_enabled
  from pybind11_tests import pytypes
label_desc: Use image node_id 43 for calling a global function with example usage: test_weakref_err(create_weakref, has_callback) without return types