pygame - importing GL - very bad...

Peter Otten __peter__ at web.de
Tue Jan 1 07:56:41 EST 2013


someone wrote:

> See this code (understand why I commented out first line):
> 
> # from OpenGL.GL import *
> from OpenGL.GL import glEnable, GL_DEPTH_TEST, \
>       glShadeModel, GL_SMOOTH, glClearColor, \
>       GL_CULL_FACE, GL_BLEND, glBlendFunc, \
>       GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, \
>       glClear, GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, \
>       glLoadIdentity, glTranslate, glRotate, \
>       glMultMatrixf, glPushMatrix, glCallList, \
>       glPopMatrix, glDisable, GL_LIGHTING
> 
> The reason why I commented out the first line is that I use "pylint" and
> it reports: "[W] Redefining built-in 'format'" for this line.
> 
> From: http://www.logilab.org/card/pylintfeatures tell:
> W0621: Redefining name %r from outer scope (line %s) Used when a
> variable's name hide a name defined in the outer scope.
> 
> I don't like to redefine already defined names so therefore I had to
> outcomment first line and then keep on adding stuff until I could run my
> program... But this SUCKS! I can see that pygame hasn't been updated for
> a long while - not many users use it? I'm not very happy about this...
> 
> Any good / clever solution to this problem, so I avoid this nasty crappy
> work-around?
> 
> Any ideas / suggestions ?
> Thanks.

It turns out pylint is lying. The situation is equivalent to

$ cat module.py
for format in [42]:
    pass
del format

$ cat main.py 
original_format = format
from module import *
assert format is original_format
$ python main.py

The assert doesn't trigger, so format is not redefined. But pylint complains 
anyway:

$ pylint main.py -rn
No config file found, using default configuration
************* Module main
W:  2: Redefining built-in 'format'
C:  1: Missing docstring
C:  1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
(__.*__))$)
W:  2: Wildcard import module

If you can ignore the warning about the wildcard import you should be able 
to ignore the "redefining built-in" warning, too. Personally I would avoid 
putting magic comments like

from module import * # pylint: disable=W0622

$ pylint main.py -rn
No config file found, using default configuration
************* Module main
I:  2: Locally disabling W0622
C:  1: Missing docstring
C:  1: Invalid name "original_format" (should match (([A-Z_][A-Z0-9_]*)|
(__.*__))$)
W:  2: Wildcard import module

into the code.




More information about the Python-list mailing list