21
21
from typing import Any , Callable
22
22
23
23
from . import Image , _imagingmath
24
- from ._deprecate import deprecate
25
24
26
25
27
26
class _Operand :
@@ -233,11 +232,7 @@ def imagemath_convert(self: _Operand, mode: str) -> _Operand:
233
232
}
234
233
235
234
236
- def lambda_eval (
237
- expression : Callable [[dict [str , Any ]], Any ],
238
- options : dict [str , Any ] = {},
239
- ** kw : Any ,
240
- ) -> Any :
235
+ def lambda_eval (expression : Callable [[dict [str , Any ]], Any ], ** kw : Any ) -> Any :
241
236
"""
242
237
Returns the result of an image function.
243
238
@@ -246,23 +241,13 @@ def lambda_eval(
246
241
:py:func:`~PIL.Image.merge` function.
247
242
248
243
:param expression: A function that receives a dictionary.
249
- :param options: Values to add to the function's dictionary. Deprecated.
250
- You can instead use one or more keyword arguments.
251
244
:param **kw: Values to add to the function's dictionary.
252
245
:return: The expression result. This is usually an image object, but can
253
246
also be an integer, a floating point value, or a pixel tuple,
254
247
depending on the expression.
255
248
"""
256
249
257
- if options :
258
- deprecate (
259
- "ImageMath.lambda_eval options" ,
260
- 12 ,
261
- "ImageMath.lambda_eval keyword arguments" ,
262
- )
263
-
264
250
args : dict [str , Any ] = ops .copy ()
265
- args .update (options )
266
251
args .update (kw )
267
252
for k , v in args .items ():
268
253
if isinstance (v , Image .Image ):
@@ -275,11 +260,7 @@ def lambda_eval(
275
260
return out
276
261
277
262
278
- def unsafe_eval (
279
- expression : str ,
280
- options : dict [str , Any ] = {},
281
- ** kw : Any ,
282
- ) -> Any :
263
+ def unsafe_eval (expression : str , ** kw : Any ) -> Any :
283
264
"""
284
265
Evaluates an image expression. This uses Python's ``eval()`` function to process
285
266
the expression string, and carries the security risks of doing so. It is not
@@ -291,29 +272,19 @@ def unsafe_eval(
291
272
:py:func:`~PIL.Image.merge` function.
292
273
293
274
:param expression: A string containing a Python-style expression.
294
- :param options: Values to add to the evaluation context. Deprecated.
295
- You can instead use one or more keyword arguments.
296
275
:param **kw: Values to add to the evaluation context.
297
276
:return: The evaluated expression. This is usually an image object, but can
298
277
also be an integer, a floating point value, or a pixel tuple,
299
278
depending on the expression.
300
279
"""
301
280
302
- if options :
303
- deprecate (
304
- "ImageMath.unsafe_eval options" ,
305
- 12 ,
306
- "ImageMath.unsafe_eval keyword arguments" ,
307
- )
308
-
309
281
# build execution namespace
310
282
args : dict [str , Any ] = ops .copy ()
311
- for k in [ * options , * kw ] :
283
+ for k in kw :
312
284
if "__" in k or hasattr (builtins , k ):
313
285
msg = f"'{ k } ' not allowed"
314
286
raise ValueError (msg )
315
287
316
- args .update (options )
317
288
args .update (kw )
318
289
for k , v in args .items ():
319
290
if isinstance (v , Image .Image ):
@@ -337,32 +308,3 @@ def scan(code: CodeType) -> None:
337
308
return out .im
338
309
except AttributeError :
339
310
return out
340
-
341
-
342
- def eval (
343
- expression : str ,
344
- _dict : dict [str , Any ] = {},
345
- ** kw : Any ,
346
- ) -> Any :
347
- """
348
- Evaluates an image expression.
349
-
350
- Deprecated. Use lambda_eval() or unsafe_eval() instead.
351
-
352
- :param expression: A string containing a Python-style expression.
353
- :param _dict: Values to add to the evaluation context. You
354
- can either use a dictionary, or one or more keyword
355
- arguments.
356
- :return: The evaluated expression. This is usually an image object, but can
357
- also be an integer, a floating point value, or a pixel tuple,
358
- depending on the expression.
359
-
360
- .. deprecated:: 10.3.0
361
- """
362
-
363
- deprecate (
364
- "ImageMath.eval" ,
365
- 12 ,
366
- "ImageMath.lambda_eval or ImageMath.unsafe_eval" ,
367
- )
368
- return unsafe_eval (expression , _dict , ** kw )
0 commit comments