This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: execfile -> type() created objects w/ no __module__ error
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: anthonybaxter Nosy List: anthonybaxter, mwh
Priority: normal Keywords:

Created on 2004-06-04 15:46 by anthonybaxter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mod.patch anthonybaxter, 2004-06-04 16:27 Objects/typeobject.c patch
Messages (6)
msg21031 - (view) Author: Anthony Baxter (anthonybaxter) (Python triager) Date: 2004-06-04 15:46
Apologies for the imprecise summary - I have no idea
where the problem is here. 

Thanks to JP Calderone for this little horror.

(distilled down from his example)

bonanza% cat foo.py 
print type('F', (object,), {})().__class__.__module__
bonanza% python2.3 -c "execfile('foo.py', {})"
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "foo.py", line 1, in ?
    print type('F', (object,), {})().__class__.__module__
SystemError: error return without exception set
bonanza% python2.4 -c "execfile('foo.py', {})"
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "foo.py", line 1, in ?
    print type('F', (object,), {})().__class__.__module__
SystemError: error return without exception set
msg21032 - (view) Author: Anthony Baxter (anthonybaxter) (Python triager) Date: 2004-06-04 16:27
Logged In: YES 
user_id=29957

The attached patch fixes this to raise an AttributeError if
the object has no __module__. The other approach to fixing
it would be to make sure that the object created always gets
a __module__, but I have no idea in that case what a
reasonable fix would be.

msg21033 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-06-04 16:36
Logged In: YES 
user_id=6656

Ah, I was about to attach the same test :-)

Do add a test and use PEP 7 code if you check it in...
msg21034 - (view) Author: Anthony Baxter (anthonybaxter) (Python triager) Date: 2004-06-04 16:49
Logged In: YES 
user_id=29957

Is it better to fix this here, or in the type() call to make
sure there's always a __module__ ?
msg21035 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-06-11 14:03
Logged In: YES 
user_id=6656

I don't think there's an answer to that.

OTOH, I think it's more important that this gets fixed than that it 
gets fixed 100% perfectly.  IOW, do what you like, but please do 
something :-)
msg21036 - (view) Author: Anthony Baxter (anthonybaxter) (Python triager) Date: 2004-06-11 15:13
Logged In: YES 
user_id=29957

Fix checked in, will be in 2.4a1 and 2.3.5.
Objects/typeobject 2.259, 2.241.6.10
Misc/NEWS 1.999,  1.831.4.120

History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40346
2004-06-04 15:46:17anthonybaxtercreate