Skip to content

Commit 02b31b1

Browse files
committed
Archive experimental code from video meet with @rainwoodman 2024-02-15
1 parent 0731b71 commit 02b31b1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_pickling.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ def test_pickle_simple_callable(protocol):
1919
assert b"simple_callable" in serialized
2020
deserialized = pickle.loads(serialized)
2121
assert deserialized() == 20220426
22+
assert deserialized is m.simple_callable
23+
orig_red = m.simple_callable.__reduce_ex__(protocol)
24+
desz_red = deserialized.__reduce_ex__(protocol)
25+
orig_fr = orig_red[1][0]
26+
desz_fr = desz_red[1][0]
27+
assert orig_fr is desz_fr
28+
seri_orig_fr = pickle.dumps(orig_fr)
29+
desz_orig_fr = pickle.loads(seri_orig_fr)
30+
print(f"\nLOOOK {dir(m.simple_callable)=}")
31+
print(f"\nLOOOK {repr(orig_fr)=}")
32+
print(f"\nLOOOK {repr(m.simple_callable.__self__)=}")
33+
print(f"\nLOOOK {dir(type(m.simple_callable))=}")
34+
print(f"\nLOOOK {repr(desz_orig_fr)=}", flush=True)
35+
36+
"""
37+
38+
(<built-in function eval>, ("__import__('importlib').import_module('pybind11_tests.pickling').simple_callable.__self__",))
39+
40+
LOOOK repr(orig_fr)='<pybind11_detail_function_record_v1__gcc_libstdcpp_cxxabi1018_sh_def object at 0x7efd316d9f70>'
41+
42+
LOOOK repr(m.simple_callable.__self__)='<pybind11_detail_function_record_v1__gcc_libstdcpp_cxxabi1018_sh_def object at 0x7efd316d9f70>'
43+
44+
LOOOK dir(type(m.simple_callable))=['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']
45+
46+
LOOOK repr(desz_orig_fr)="<module 'pybind11_tests.pickling'>"
47+
48+
"""
2249

2350

2451
@pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"])

0 commit comments

Comments
 (0)