From 73a5f7e83b391ba3df4f55d3607a43f6fdfda534 Mon Sep 17 00:00:00 2001 From: "[6~" Date: Mon, 18 Nov 2019 18:03:02 -0600 Subject: [PATCH 1/2] Remove overriding of constant mapper in CompileMapper --- pymbolic/compiler.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py index c652d52..96ff2c9 100644 --- a/pymbolic/compiler.py +++ b/pymbolic/compiler.py @@ -29,26 +29,21 @@ from pymbolic.mapper.stringifier import (StringifyMapper, PREC_NONE, PREC_SUM, PREC_POWER) -def _constant_mapper(c): - # work around numpy bug #1137 (locale-sensitive repr) - # http://projects.scipy.org/numpy/ticket/1137 - try: - import numpy - except ImportError: - pass - else: - if isinstance(c, numpy.floating): - c = float(c) - elif isinstance(c, numpy.complexfloating): - c = complex(c) - - return repr(c) - - class CompileMapper(StringifyMapper): - def __init__(self): - StringifyMapper.__init__(self, - constant_mapper=_constant_mapper) + def map_constant(self, expr, enclosing_prec): + # work around numpy bug #1137 (locale-sensitive repr) + # http://projects.scipy.org/numpy/ticket/1137 + try: + import numpy + except ImportError: + pass + else: + if isinstance(expr, numpy.floating): + expr = float(expr) + elif isinstance(expr, numpy.complexfloating): + expr = complex(expr) + + return repr(expr) def map_polynomial(self, expr, enclosing_prec): # Use Horner's scheme to evaluate the polynomial -- GitLab From ba8ee22cd396f1edd3fc75f8d15ecd862e224659 Mon Sep 17 00:00:00 2001 From: "[6~" Date: Mon, 18 Nov 2019 18:03:23 -0600 Subject: [PATCH 2/2] Add stacklevel to constant_mapper deprecation warning --- pymbolic/mapper/stringifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index f1afc0f..79fd743 100644 --- a/pymbolic/mapper/stringifier.py +++ b/pymbolic/mapper/stringifier.py @@ -95,7 +95,7 @@ class StringifyMapper(pymbolic.mapper.Mapper): "achieve the desired effect. " "The 'constant_mapper' argument will " "disappear after June 2020.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) self.constant_mapper = constant_mapper -- GitLab