Gimp-Forum.net
What's up with the all caps TRUE and FALSE ? - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: What's up with the all caps TRUE and FALSE ? (/Thread-What-s-up-with-the-all-caps-TRUE-and-FALSE)



What's up with the all caps TRUE and FALSE ? - ChameleonScales - 10-15-2021

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)



RE: What's up with the all caps TRUE and FALSE ? - Ofnuts - 10-16-2021

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: )


RE: What's up with the all caps TRUE and FALSE ? - ChameleonScales - 10-16-2021

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.