mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-37444: Update differing exception between builtins and importlib (GH-14869)
Imports now raise `TypeError` instead of `ValueError` for relative import failures. This makes things consistent between `builtins.__import__` and `importlib.__import__` as well as using a more natural import for the failure. https://bugs.python.org/issue37444 Automerge-Triggered-By: @brettcannon
This commit is contained in:
parent
8e568ef266
commit
c5fa44944e
9 changed files with 134 additions and 108 deletions
|
@ -873,7 +873,7 @@ def _resolve_name(name, package, level):
|
|||
"""Resolve a relative module name to an absolute one."""
|
||||
bits = package.rsplit('.', level - 1)
|
||||
if len(bits) < level:
|
||||
raise ValueError('attempted relative import beyond top-level package')
|
||||
raise ImportError('attempted relative import beyond top-level package')
|
||||
base = bits[0]
|
||||
return '{}.{}'.format(base, name) if name else base
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue