Issue1607

classification
Title: jython __import__ does not accept '' for globals
Type: behaviour Severity: normal
Components: Core Versions: 2.5b1
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: pjenvey, sven, thijs, zyasoft
Priority: low Keywords:

Created on 2010-05-06.15:35:39 by sven, last changed 2010-08-06.06:14:41 by zyasoft.

Messages
msg5762 (view) Author: Sven Klemm (sven) Date: 2010-05-06.15:35:37
In Jython the __import__ function works differently than the one in CPython, CPython allows an empty string as globals while Jython doesn't.

__import__('csv','') works in CPython while it doesn't work in Jython

svekle@blackdevil:~> jython             
Jython 2.5.1+ (unknown:exported, May 6 2010, 12:31:38) 
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_15
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__('csv','')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: str indices must be integers

svekle@blackdevil:~> python2.5
Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__('csv','')
<module 'csv' from '/usr/lib/python2.5/csv.pyc'>
msg5794 (view) Author: Philip Jenvey (pjenvey) Date: 2010-06-03.02:37:07
I seem to recall this issue coming up before, but I'm not sure and can't recall the details.

Regardless, I strongly recommend you use None here instead. '' here is bad practice, and could go away in the future
msg5944 (view) Author: Jim Baker (zyasoft) Date: 2010-08-06.05:54:03
Please use a mapping for globals or locals. CPython behavior here is too sloppy to be worthwhile replicating for Jython.
msg5945 (view) Author: Jim Baker (zyasoft) Date: 2010-08-06.06:14:41
I should point out, if the purpose of this is to workaround some code that needs the CPython behavior, you can always patch the builtin __import__ function. Some examples of changing builtins are in test_sys_jy.py, and could be introduced through possibly sitecustomize.py.
History
Date User Action Args
2010-08-06 06:14:41zyasoftsetmessages: + msg5945
2010-08-06 05:54:03zyasoftsetstatus: open -> closed
resolution: wont fix
messages: + msg5944
nosy: + zyasoft
2010-06-17 07:49:05thijssetnosy: + thijs
2010-06-03 02:37:07pjenveysetpriority: low
nosy: + pjenvey
messages: + msg5794
2010-05-06 15:35:39svencreate