This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Importlib, more verbosity please
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Lukáš.Němec, brett.cannon, python-dev
Priority: low Keywords:

Created on 2013-07-30 10:30 by Lukáš.Němec, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg193922 - (view) Author: Lukáš Němec (Lukáš.Němec) Date: 2013-07-30 10:30
Hello,

recently I filed this bugreport to Django, but they clarified this by pointing me to commits for new version of Django that uses python builtin importlib (import_module)

But since most of their import_module code is done like [import_module(x) for y if blahblah], it is very difficult for me to debug code where Django tries to import some package, and all I get back is message "relative imports require the 'package' argument"

This message tells me exactly nothing :), just that something somewhere, even 3rd party app tried to do relative imports ...

what did it import, with what parameters?

I edited this locally for debugging, and changed it to this:
"relative imports require the 'package' argument, package: %s" % name

This simple change of the message allowed me to find the problem in a few seconds..

Would you please consider adding something similar to importlib for better debugging?

Thank you :)
msg193925 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-07-30 12:43
It could be changed to something like "the 'package' argument is required to perform a relative import for {!r}".format(name) . Would that have made it more clear?
msg193926 - (view) Author: Lukáš Němec (Lukáš.Němec) Date: 2013-07-30 12:45
Yes, absolutely,

that is what was I needed to debug it easily, the name parameter

Thank you :)
msg193927 - (view) Author: Lukáš Němec (Lukáš.Němec) Date: 2013-07-30 12:46
Also, please do not forget on backports for python 2.6+ :)
msg193933 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-07-30 13:34
Sorry, I can't backport this change as it's not a bugfix but an enhancement and it could break someone's code who relies on the specific format of the exception message.
msg194973 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-08-12 17:29
New changeset 2294594fbe6c by Brett Cannon in branch 'default':
Closes issue #18598: Have the exception message for
http://hg.python.org/cpython/rev/2294594fbe6c
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62798
2013-08-12 17:29:45brett.cannonsetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2013-08-12 17:29:21python-devsetnosy: + python-dev
messages: + msg194973
2013-07-30 13:34:00brett.cannonsetmessages: + msg193933
2013-07-30 12:46:17Lukáš.Němecsetmessages: + msg193927
2013-07-30 12:45:14Lukáš.Němecsetmessages: + msg193926
2013-07-30 12:43:37brett.cannonsetpriority: normal -> low

assignee: brett.cannon
versions: + Python 3.4
nosy: + brett.cannon

messages: + msg193925
stage: needs patch
2013-07-30 10:30:44Lukáš.Němeccreate