Objects: Make bool an int

We can't inherit from bool, so __new__ can't return a bool, so
everything has be done with int.  However __bool__ is already
defined for int, so it should have no significant impact
(other than type() calls).

Fixes issue 232.
This commit is contained in:
Mike Auty
2020-06-18 16:53:14 +01:00
parent 0ffe318cb0
commit 16a8e3771b
+4 -1
View File
@@ -156,9 +156,12 @@ class PrimitiveObject(interfaces.objects.ObjectInterface):
return self._context.layers.write(self.vol.layer_name, self.vol.offset, data)
# This must be int (and the _struct_type must be int) because bool cannot be inherited from:
# https://mail.python.org/pipermail/python-dev/2002-March/020822.html
# https://mail.python.org/pipermail/python-dev/2004-February/042537.html
class Boolean(PrimitiveObject, int):
"""Primitive Object that handles boolean types."""
_struct_type = bool # type: ClassVar[Type]
_struct_type = int # type: ClassVar[Type]
class Integer(PrimitiveObject, int):