Skip to content

Commit

Permalink
notes and better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Jun 2, 2024
1 parent 7dd2640 commit 48f8724
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ubelt/util_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def schedule_deprecation(modname=None, name='?', type='?', migration='',
module = sys.modules[modname]
current = Version(module.__version__)
else:
# TODO: use the inspect module to get the function / module this was
# called from and fill in unspecified values.
current = 'unknown'

def _handle_when(when, default):
Expand All @@ -190,6 +192,7 @@ def _handle_when(when, default):
remove_now, remove_str = _handle_when(remove, default=False)
error_now, error_str = _handle_when(error, default=False)

# TODO: make the message more customizable.
msg = (
'The "{name}" {type} was deprecated{deprecate_str}, will cause '
'an error{error_str} and will be removed{remove_str}. The current '
Expand Down
7 changes: 4 additions & 3 deletions ubelt/util_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,10 @@ def _custom_import_modpath(modpath, index=-1):
with PythonPathContext(dpath, index=index):
module = import_module_from_name(modname)
except Exception as ex: # nocover
msg_parts = [
'ERROR: Failed to import modname={} with modpath={}'.format(
modname, modpath)
msg_parts = [(
'ERROR: Failed to import modname={} with modpath={} and '
'sys.path modified with {} at index={}').format(
modname, modpath, repr(dpath), index)
]
msg_parts.append('Caused by: {}'.format(repr(ex)))
raise RuntimeError('\n'.join(msg_parts))
Expand Down

0 comments on commit 48f8724

Please sign in to comment.