Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0"

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 9, 2012, 1:04 PM

Post #1 of 12 (270 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0"

New submission from Dave Malcolm:

I've been testing various 3rd-party python code against 3.3b1, and see
ValueError: level must be >= 0
exceptions where C code is using PyImport_ImportModuleEx.

PyImport_ImportModuleEx reads as
63 #define PyImport_ImportModuleEx(n, g, l, f) \
64 PyImport_ImportModuleLevel(n, g, l, f, -1)
within http://hg.python.org/cpython/file/aaa68dce117e/Include/import.h as of now (2012-08-09)

Within PyImport_ImportModuleLevel there's this check:
1280 if (level < 0) {
1281 PyErr_SetString(PyExc_ValueError, "level must be >= 0");
1282 goto error;
1283 }
which thus always fires.

So it would seem that currently any usage of PyImport_ImportModuleEx will fail.

----------
components: Interpreter Core
messages: 167828
nosy: dmalcolm
priority: normal
severity: normal
status: open
title: PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0"
type: behavior
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 1:15 PM

Post #2 of 12 (258 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Dave Malcolm added the comment:

(FWIW, this was observed when compiling pygobject-3.3.4 against Python-3.3.0b1)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 1:53 PM

Post #3 of 12 (257 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Changes by STINNER Victor <victor.stinner [at] gmail>:


----------
nosy: +brett.cannon

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 1:54 PM

Post #4 of 12 (256 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

STINNER Victor added the comment:

Can you please try my amazing patch?

----------
keywords: +patch
nosy: +haypo
Added file: http://bugs.python.org/file26751/amazing_patch.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 2:04 PM

Post #5 of 12 (264 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

STINNER Victor added the comment:

Oh, I didn't realize that the documentation says that the default value is -1.
http://docs.python.org/library/functions.html#__import__

"level specifies whether to use absolute or relative imports. The default is -1 which indicates both absolute and relative imports will be attempted. 0 means only perform absolute imports. Positive values for level indicate the number of parent directories to search relative to the directory of the module calling __import__()."

We should probably tolerate -1, or just drop the exception.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 2:07 PM

Post #6 of 12 (258 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Dave Malcolm added the comment:

On Thu, 2012-08-09 at 21:04 +0000, STINNER Victor wrote:
> STINNER Victor added the comment:
>
> Oh, I didn't realize that the documentation says that the default value is -1.
> http://docs.python.org/library/functions.html#__import__
>
> "level specifies whether to use absolute or relative imports. The default is -1 which indicates both absolute and relative imports will be attempted. 0 means only perform absolute imports. Positive values for level indicate the number of parent directories to search relative to the directory of the module calling __import__()."
That's the python 2 documentation

The 3.3 docs here:
http://docs.python.org/dev/library/functions.html#__import__
say "Changed in version 3.3: Negative values for level are no longer
supported (which also changes the default value to 0)."

> We should probably tolerate -1, or just drop the exception.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 2:59 PM

Post #7 of 12 (252 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Antoine Pitrou added the comment:

Sounds like a rather annoying regression. Changing the macro's expansion would be good enough IMO.

----------
nosy: +georg.brandl, pitrou
priority: normal -> release blocker

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 3:07 PM

Post #8 of 12 (251 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

STINNER Victor added the comment:

> Sounds like a rather annoying regression.

PyImport_ImportModuleLevel() is part of the stable API. Is it an
acceptable to not only change the default value but also fail with the
previous *default* value?

Can't we just drop the check "level < 0"?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 9, 2012, 3:53 PM

Post #9 of 12 (249 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Eric Snow added the comment:

> Changing the macro's expansion would be good enough IMO.

Sounds good to me.

> PyImport_ImportModuleLevel() is part of the stable API...

>From what I understand, as long as the function header has not changed, the stable ABI is still stable.

> Can't we just drop the check "level < 0"?

In Python 3 a negative value makes no sense, since there are no accommodations for implicit relative imports. The fact that builtins.__import__() accommodated -1 still was an oversight that was corrected in 3.3. Looks like this is just one bit that got missed.

----------
nosy: +eric.snow

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 8:03 AM

Post #10 of 12 (250 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Brett Cannon added the comment:

OK, the macro expansion should get fixed, a versionchanged should probably be added to the C API docs (for PyImport_ImportModuleLevel()), and a line in What's New for porting C code should be added.

We can't go back to -1, as Eric said, because it makes no sense anymore since you can't syntactically do an import that has -1 level semantics in Python 3. The fact that __import__ accepted a negative level was a bug that went unnoticed up until this point since so few people import modules programmatically and want implicit relative imports.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 3:55 PM

Post #11 of 12 (247 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Roundup Robot added the comment:

New changeset 9804aec74d4a by Brett Cannon in branch 'default':
Issue #15610: The PyImport_ImportModuleEx macro now calls
http://hg.python.org/cpython/rev/9804aec74d4a

----------
nosy: +python-dev

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 3:56 PM

Post #12 of 12 (248 views)
Permalink
[issue15610] PyImport_ImportModuleEx always fails in 3.3 with "ValueError: level must be >= 0" [In reply to]

Brett Cannon added the comment:

Hopefully the 3rd-party code using PyImport_ImportModuleEx will work as expected with a 'level' of 0.

----------
assignee: -> brett.cannon
resolution: -> fixed
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15610>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.