Skip to content

Commit 2980163

Browse files
ConchylicultorThe etils Authors
authored and
The etils Authors
committed
Fix etils adhoc crash with module not supporting weakref
PiperOrigin-RevId: 737983119
1 parent c40ae32 commit 2980163

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Changelog follow https://keepachangelog.com/ format.
1010

1111
* `ecolab.adhoc`:
1212
* Better error message for adhoc invalidate with `epy.reraise`
13+
* Fix crash when importing module not supporting weak_ref
1314

1415
## [1.12.2] - 2025-03-10
1516

etils/ecolab/inplace_reload.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ class _ModuleRefs:
180180

181181
def save_module(self, module: types.ModuleType) -> None:
182182
"""Save reference on all previous modules/objects."""
183-
self.modules.append(weakref.ref(module))
183+
try:
184+
weak_module = weakref.ref(module)
185+
except TypeError:
186+
# Some modules, like '_bcrypt.lib' raises:
187+
# TypeError: cannot create weak reference to '_cffi_backend.Lib' object
188+
return
189+
self.modules.append(weak_module)
184190

185191
for name, old_obj in module.__dict__.items():
186192
# Only update objects part of the module (filter other imported symbols)

0 commit comments

Comments
 (0)