mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-01 08:27:30 +03:00 
			
		
		
		
	Removed unused import and restored existing checks (#1)
* Removed unused import * Restored existing checks * Restored coerce_e, _E and data property * Deprecated coerce_e Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									4e12ccc63e
								
							
						
					
					
						commit
						46802d5def
					
				|  | @ -1,5 +1,7 @@ | ||||||
| import pytest | import pytest | ||||||
| 
 | 
 | ||||||
|  | from PIL import Image | ||||||
|  | 
 | ||||||
| from .helper import assert_image_equal, hopper | from .helper import assert_image_equal, hopper | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -17,6 +19,7 @@ def test_sanity(): | ||||||
|         im.point(list(range(256))) |         im.point(list(range(256))) | ||||||
|     im.point(lambda x: x * 1) |     im.point(lambda x: x * 1) | ||||||
|     im.point(lambda x: x + 1) |     im.point(lambda x: x + 1) | ||||||
|  |     im.point(lambda x: x - 1) | ||||||
|     im.point(lambda x: x * 1 + 1) |     im.point(lambda x: x * 1 + 1) | ||||||
|     im.point(lambda x: 0.1 + 0.2 * x) |     im.point(lambda x: 0.1 + 0.2 * x) | ||||||
|     im.point(lambda x: -x) |     im.point(lambda x: -x) | ||||||
|  | @ -24,6 +27,7 @@ def test_sanity(): | ||||||
|     im.point(lambda x: 1 - x / 2) |     im.point(lambda x: 1 - x / 2) | ||||||
|     im.point(lambda x: (2 + x) / 3) |     im.point(lambda x: (2 + x) / 3) | ||||||
|     im.point(lambda x: 0.5) |     im.point(lambda x: 0.5) | ||||||
|  |     im.point(lambda x: x / 1) | ||||||
|     with pytest.raises(TypeError): |     with pytest.raises(TypeError): | ||||||
|         im.point(lambda x: x * x) |         im.point(lambda x: x * x) | ||||||
|     with pytest.raises(TypeError): |     with pytest.raises(TypeError): | ||||||
|  | @ -55,3 +59,8 @@ def test_f_mode(): | ||||||
|     im = hopper("F") |     im = hopper("F") | ||||||
|     with pytest.raises(ValueError): |     with pytest.raises(ValueError): | ||||||
|         im.point(None) |         im.point(None) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_coerce_e_deprecation(): | ||||||
|  |     with pytest.warns(DeprecationWarning): | ||||||
|  |         assert Image.coerce_e(2).data == 2 | ||||||
|  |  | ||||||
|  | @ -29,7 +29,6 @@ import builtins | ||||||
| import io | import io | ||||||
| import logging | import logging | ||||||
| import math | import math | ||||||
| import numbers |  | ||||||
| import os | import os | ||||||
| import re | import re | ||||||
| import struct | import struct | ||||||
|  | @ -431,19 +430,23 @@ def _getencoder(mode, encoder_name, args, extra=()): | ||||||
| # Simple expression analyzer | # Simple expression analyzer | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # _Affine(m, b) represents the polynomial m x + b | def coerce_e(value): | ||||||
| class _Affine: |     deprecate("coerce_e", 10) | ||||||
|     def __init__(self, m, b): |     return value if isinstance(value, _E) else _E(1, value) | ||||||
|         self.m = m | 
 | ||||||
|         self.b = b | 
 | ||||||
|  | class _E: | ||||||
|  |     def __init__(self, scale, data): | ||||||
|  |         self.scale = scale | ||||||
|  |         self.data = data | ||||||
| 
 | 
 | ||||||
|     def __neg__(self): |     def __neg__(self): | ||||||
|         return _Affine(-self.m, -self.b) |         return _E(-self.scale, -self.data) | ||||||
| 
 | 
 | ||||||
|     def __add__(self, other): |     def __add__(self, other): | ||||||
|         if isinstance(other, _Affine): |         if isinstance(other, _E): | ||||||
|             return _Affine(self.m + other.m, self.b + other.b) |             return _E(self.scale + other.scale, self.data + other.data) | ||||||
|         return _Affine(self.m, self.b + other) |         return _E(self.scale, self.data + other) | ||||||
| 
 | 
 | ||||||
|     __radd__ = __add__ |     __radd__ = __add__ | ||||||
| 
 | 
 | ||||||
|  | @ -454,21 +457,21 @@ class _Affine: | ||||||
|         return other + -self |         return other + -self | ||||||
| 
 | 
 | ||||||
|     def __mul__(self, other): |     def __mul__(self, other): | ||||||
|         if isinstance(other, _Affine): |         if isinstance(other, _E): | ||||||
|             return NotImplemented |             return NotImplemented | ||||||
|         return _Affine(self.m * other, self.b * other) |         return _E(self.scale * other, self.data * other) | ||||||
| 
 | 
 | ||||||
|     __rmul__ = __mul__ |     __rmul__ = __mul__ | ||||||
| 
 | 
 | ||||||
|     def __truediv__(self, other): |     def __truediv__(self, other): | ||||||
|         if isinstance(other, _Affine): |         if isinstance(other, _E): | ||||||
|             return NotImplemented |             return NotImplemented | ||||||
|         return _Affine(self.m / other, self.b / other) |         return _E(self.scale / other, self.data / other) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _getscaleoffset(expr): | def _getscaleoffset(expr): | ||||||
|     a = expr(_Affine(1.0, 0.0)) |     a = expr(_E(1, 0)) | ||||||
|     return (a.m, a.b) if isinstance(a, _Affine) else (0.0, a) |     return (a.scale, a.data) if isinstance(a, _E) else (0, a) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # -------------------------------------------------------------------- | # -------------------------------------------------------------------- | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user