Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Changelog follow https://keepachangelog.com/ format.
consistency with `ecolab.adhoc`
* Added: `epy.pretty_repr_top_level`
* Added: `epy.wraps_cls` equivalent of `functools.wraps` but for classes.
* Breaking: `epy.lazy_imports(error_callback=)` has now signature
`(Exception) -> None` (instead of `(str) -> None`)
* Fixed: `epy.pretty_repr` missing trailing `,` for tuple with single
element.
* `ecolab`:
Expand Down
10 changes: 5 additions & 5 deletions etils/epy/lazy_imports_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import Any, Callable, Iterator


_ErrorCallback = Callable[[str], None]
_ErrorCallback = Callable[[Exception], None]
_SuccessCallback = Callable[[str], None]


Expand Down Expand Up @@ -68,9 +68,9 @@ def _module(self) -> types.ModuleType:
if self.success_callback is not None:
self.success_callback(self.module_name)
return module
except ImportError:
except ImportError as e:
if self.error_callback is not None:
self.error_callback(self.module_name)
self.error_callback(e)
raise

def __getattr__(self, name: str) -> Any:
Expand Down Expand Up @@ -124,8 +124,8 @@ def lazy_imports(
the original `ecolab.adhoc` context is re-created to import the lazy module.

Args:
error_callback: a callback to trigger when an import fails. The callback is
passed the name of the imported module as an arg.
error_callback: a callback to trigger when an import fails. The exception is
passed as an arg, so user can use `epy.reraise(e, 'Additional message')`.
success_callback: a callback to trigger when an import succeeds. The
callback is passed the name of the imported module as an arg.

Expand Down
2 changes: 1 addition & 1 deletion etils/epy/lazy_imports_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_error_callback():
_ = doesnotexist.stack
except ImportError:
pass
error_callback.assert_called_once_with('doesnotexist')
error_callback.assert_called_once()
success_callback.assert_not_called()


Expand Down