22from ._imageLib
import ImageSliceF, ImageSliceD
24__all__ = (
"disableImageArithmetic",
"disableMaskArithmetic")
28 """Wrap a method providing a helpful error message about image arithmetic
33 Class in which the method
is to be defined.
42 existing = getattr(cls, attr, None)
44 def notImplemented(self, other):
45 """Provide a helpful error message about image arithmetic
47 Unless we're operating on an ImageSlice, in which case it might be
53 Image someone's attempting to do arithmetic with.
55 The operand of the arithmetic operation.
57 if existing
is not None and isinstance(other, (ImageSliceF, ImageSliceD)):
58 return existing(self, other)
59 raise NotImplementedError(
"This arithmetic operation is not implemented, in order to prevent the "
60 "accidental proliferation of temporaries. Please use the in-place "
61 "arithmetic operations (e.g., += instead of +) or operate on the "
66def disableImageArithmetic(cls):
67 """Add helpful error messages about image arithmetic"""
68 for attr
in (
"__add__",
"__sub__",
"__mul__",
"__truediv__",
69 "__radd__",
"__rsub__",
"__rmul__",
"__rtruediv__"):
73def disableMaskArithmetic(cls):
74 """Add helpful error messages about mask arithmetic"""
75 for attr
in (
"__or__",
"__and__",
"__xor__",
76 "__ror__",
"__rand__",
"__rxor__"):
The base class for all image classed (Image, Mask, MaskedImage, ...)
def wrapNotImplemented(cls, attr)