From 952685faa14e719f38cd42fc716814a113efa454 Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Fri, 19 Oct 2012 07:54:55 -0500 Subject: [PATCH] py3k: Type coercion is gone Types aren't automatically converted for operations for you. --- PIL/Image.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 4b8fc2b5e..f82e52981 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -396,11 +396,16 @@ def _getencoder(mode, encoder_name, args, extra=()): # -------------------------------------------------------------------- # Simple expression analyzer +def coerce_e(value): + return value if isinstance(value, _E) else _E(value) + class _E: - def __init__(self, data): self.data = data - def __coerce__(self, other): return self, _E(other) - def __add__(self, other): return _E((self.data, "__add__", other.data)) - def __mul__(self, other): return _E((self.data, "__mul__", other.data)) + def __init__(self, data): + self.data = data + def __add__(self, other): + return _E((self.data, "__add__", coerce_e(other).data)) + def __mul__(self, other): + return _E((self.data, "__mul__", coerce_e(other).data)) def _getscaleoffset(expr): stub = ["stub"]