[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] BUG: required modules not raising error when failing to import was Re: [pygame] Surfarray.array_alpha() bugfix, py2exe/py2app segfault



Hi Marcus and Zack,

mva@xxxxxxxxxxxx wrote:

Zack Schilling <zack.schilling@xxxxxxxxx>:


[snip]
I think some documentation or a quick exception when the package fails
to load would be sufficient.  Wouldn't it make more sense to change
"import_pygame_bufferproxy()" in pygame.h to throw an exception with a
helpful message?

That's usually done by the C API already. pygame's current __init__.py
however hides nearly all import errors and sets up some lambda expressions
that cause code to fail badly in case the module could not be imported
correctly. To fix the import issue, the initialisation system has to be fixed
first.

Kind off, sort off, but not intensionally. If an import_pygame_whatever is at the end of the module init function the ImportError is propagated. But many Pygame extension modules import several other modules, and no explicit error checking is done. So import errors are cleared. I have just adding error checks to imports and am now testing it. There won't be any "helpful message". It is just a regular import error message. And it won't be an ImportError, but rather a NotImplementedError. However, the original error message is preserved and displayed, so the missing module is known. Here is an example:

pixels_alpha.py:3: RuntimeWarning: import display: No module named bufferproxy
(ImportError: No module named bufferproxy)
 import os, sys, pygame, numpy
Traceback (most recent call last):
 File "pixels_alpha.py", line 35, in <module>
   if __name__ == '__main__': main()
 File "pixels_alpha.py", line 13, in main
   screen = pygame.display.set_mode((500,500))
File "C:\PYTHON25\Lib\site-packages\pygame\__init__.py", line 69, in __getattr__
   raise NotImplementedError, MissingPygameModule
NotImplementedError: display module not available
(ImportError: No module named bufferproxy)


Lenard

--
Lenard Lindstrom
<len-l@xxxxxxxxx>