Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's up with the all caps TRUE and FALSE ?
#1
In gimpfu, TRUE is not a boolean but an instance:


Code:
➤> type(TRUE)
<type 'instance'>


I'm wondering why it was made that way and whether it can have unwanted consequences to use python's boolean "True" instead in commands of this kind:

Code:
pdb.gimp_edit_paste(channel, True)
Reply
#2
Well:
Code:
➤> TRUE
True
➤> dir(TRUE)
['__cmp__', '__doc__', '__init__', '__int__', '__module__', '__nonzero__', '__repr__', '__str__', '_deprecated', '_name', '_suggestion', '_v']
➤> TRUE.__module__
'gimpenums'

And gimpenums.py in all its glory:
Code:
from _gimpenums import *

# This is from pygtk/gtk/__init__.py
# Copyright (C) 1998-2003  James Henstridge

class _DeprecatedConstant:
    def __init__(self, value, name, suggestion):
        self._v = value
        self._name = name
        self._suggestion = suggestion

    def _deprecated(self, value):
        import warnings
        message = '%s is deprecated, use %s instead' % (self._name,
                                                        self._suggestion)
        warnings.warn(message, DeprecationWarning, 3)
        return value

    __nonzero__ = lambda self: self._deprecated(self._v == True)
    __int__     = lambda self: self._deprecated(int(self._v))
    __str__     = lambda self: self._deprecated(str(self._v))
    __repr__    = lambda self: self._deprecated(repr(self._v))
    __cmp__     = lambda self, other: self._deprecated(cmp(self._v, other))

TRUE = _DeprecatedConstant(True, 'gimpenums.TRUE', 'True')
FALSE = _DeprecatedConstant(False, 'gimpenums.FALSE', 'False')

del _DeprecatedConstant

So I think this means you should use True instead: )
Reply
#3
Thanks, that clarifies it.
I didn't get that deprecation warning that gimpenums.py seems to be there for though. I hope that's normal.
Reply


Forum Jump: