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.

Title: importlib: '.submodule' is not a relative name (no leading dot)
Type: behavior Stage: resolved
Components: Versions: Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, martin.panter, python-dev
Priority: normal Keywords: easy

Created on 2015-12-01 05:31 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg255642 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-12-01 05:31
>>> import importlib.util
>>> importlib.util.resolve_name(".submodule", None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/proj/python/cpython/Lib/importlib/", line 26, in resolve_name
    '(no leading dot)'.format(name))
ValueError: '.submodule' is not a relative name (no leading dot)

This message sounds like nonsense. Perhaps the it should say something like:

    '.submodule' should be an absolute name (no leading dot)


    relative import of '.submodule' not allowed outside of a package
msg255654 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-12-01 15:42
So both proposed messages are correct depending on what you want to accomplish; it all depends on whether the leading dot was the mistake or the missing package was.

And the message does make some sense if you read it more like "'.submodule' is not a relative name (drop the leading dot)". I do agree, though, it's hard to read as written.
msg255895 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-04 23:19
New changeset b3a0765671d6 by Brett Cannon in branch 'default':
Issue #25771: Tweak ValueError message when package isn't specified
msg255896 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-12-04 23:20
Fixed in default (left 3.5 alone since it technically isn't a bug fix but a clarification; fine if someone else wants to handle the backport).
msg255909 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-12-05 00:19
Thanks, the fix is fine and there is no big need to backport it. For the record, I only came across this playing with runpy. Old message:

$ python3 -m .submodule
/sbin/python3: Error while finding spec for '.submodule' (<class 'ValueError'>: '.submodule' is not a relative name (no leading dot))

New message:

$ ./python -m .submodule
/media/disk/home/proj/python/cpython/python: Error while finding spec for '.submodule' (<class 'ValueError'>: no package specified for '.submodule' (required for relative module names))
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69957
2015-12-05 00:19:14martin.pantersetmessages: + msg255909
versions: - Python 3.4, Python 3.5
2015-12-04 23:20:54brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg255896

stage: resolved
2015-12-04 23:19:53python-devsetnosy: + python-dev
messages: + msg255895
2015-12-01 15:42:22brett.cannonsetassignee: brett.cannon

messages: + msg255654
nosy: + brett.cannon
2015-12-01 05:31:34martin.pantercreate