mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
importlib.__import__() now raises ValueError when level < 0.
This is to bring it more in line with what PEP 328 set out to do with removing ambiguous absolute/relative import semantics.
This commit is contained in:
parent
7fab676e87
commit
3b1a06c1ea
3 changed files with 12 additions and 0 deletions
|
|
@ -1048,6 +1048,8 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
|
|||
raise TypeError("module name must be str, not {}".format(type(name)))
|
||||
if level == 0:
|
||||
module = _gcd_import(name)
|
||||
elif level < 0:
|
||||
raise ValueError('level must be >= 0')
|
||||
else:
|
||||
package = _calc___package__(globals)
|
||||
module = _gcd_import(name, package, level)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue