Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importlib: '.submodule' is not a relative name (no leading dot) #69957

Closed
vadmium opened this issue Dec 1, 2015 · 5 comments
Closed

importlib: '.submodule' is not a relative name (no leading dot) #69957

vadmium opened this issue Dec 1, 2015 · 5 comments
Assignees
Labels
easy type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Dec 1, 2015

BPO 25771
Nosy @brettcannon, @vadmium

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/brettcannon'
closed_at = <Date 2015-12-04.23:20:54.862>
created_at = <Date 2015-12-01.05:31:34.060>
labels = ['easy', 'type-bug']
title = "importlib: '.submodule' is not a relative name (no leading dot)"
updated_at = <Date 2015-12-05.00:19:14.124>
user = 'https://github.com/vadmium'

bugs.python.org fields:

activity = <Date 2015-12-05.00:19:14.124>
actor = 'martin.panter'
assignee = 'brett.cannon'
closed = True
closed_date = <Date 2015-12-04.23:20:54.862>
closer = 'brett.cannon'
components = []
creation = <Date 2015-12-01.05:31:34.060>
creator = 'martin.panter'
dependencies = []
files = []
hgrepos = []
issue_num = 25771
keywords = ['easy']
message_count = 5.0
messages = ['255642', '255654', '255895', '255896', '255909']
nosy_count = 3.0
nosy_names = ['brett.cannon', 'python-dev', 'martin.panter']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25771'
versions = ['Python 3.6']

@vadmium
Copy link
Member Author

vadmium commented Dec 1, 2015

>>> 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/util.py", 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)

or:

relative import of '.submodule' not allowed outside of a package

@vadmium vadmium added easy type-bug An unexpected behavior, bug, or error labels Dec 1, 2015
@brettcannon
Copy link
Member

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.

@brettcannon brettcannon self-assigned this Dec 1, 2015
@python-dev
Copy link
Mannequin

python-dev mannequin commented Dec 4, 2015

New changeset b3a0765671d6 by Brett Cannon in branch 'default':
Issue bpo-25771: Tweak ValueError message when package isn't specified
https://hg.python.org/cpython/rev/b3a0765671d6

@brettcannon
Copy link
Member

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).

@vadmium
Copy link
Member Author

vadmium commented Dec 5, 2015

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))

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants