From 768b49750fd2a9ba4382f44960108b985d0ac405 Mon Sep 17 00:00:00 2001 From: "[6~" Date: Thu, 17 Oct 2019 14:23:07 -0500 Subject: [PATCH] Deprecate Stringifier.constant_mapper --- pymbolic/mapper/stringifier.py | 20 ++++++++++++++------ pymbolic/primitives.py | 12 +++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index da65138..f1afc0f 100644 --- a/pymbolic/mapper/stringifier.py +++ b/pymbolic/mapper/stringifier.py @@ -87,11 +87,16 @@ class StringifyMapper(pymbolic.mapper.Mapper): method to get a :class:`StringifyMapper` that potentially does. """ - def __init__(self, constant_mapper=str): - """ - :arg constant_mapper: A function of a single *expr* argument being used - to map constants into strings. - """ + def __init__(self, constant_mapper=None): + if constant_mapper is not None: + from warnings import warn + warn("Overriding constant_mapper is deprecated. " + "Instead, subclass the stringifier to " + "achieve the desired effect. " + "The 'constant_mapper' argument will " + "disappear after June 2020.", + DeprecationWarning) + self.constant_mapper = constant_mapper # {{{ replaceable string composition interface @@ -140,7 +145,10 @@ class StringifyMapper(pymbolic.mapper.Mapper): expr, enclosing_prec, *args, **kwargs) def map_constant(self, expr, enclosing_prec, *args, **kwargs): - result = self.constant_mapper(expr) + if self.constant_mapper is None: + result = str(expr) + else: + result = self.constant_mapper(expr) if not (result.startswith("(") and result.endswith(")")) \ and ("-" in result or "+" in result) \ diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index 88cf8f5..0ca0a6d 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -452,9 +452,8 @@ class Expression(object): a subclass of :class:`pymbolic.mapper.stringifier.StringifyMapper`. :arg originating_stringifier: If provided, the newly created - stringifier should use attributes and settings of - *originating_stringifier*, e.g. the - :attr:`pymbolic.mapper.StringifyMapper.constant_mapper`. + stringifier should carry forward attributes and settings of + *originating_stringifier*. """ if originating_stringifier is None: stringify_mapper_args = () @@ -469,8 +468,11 @@ class Expression(object): else: from warnings import warn warn("%s overrides 'stringifier', which is deprecated. " - "Override 'make_stringifier' instead." - % type(self).__name__) + "Override 'make_stringifier' instead. " + "Backward compatibility will go away " + "sometime after June 2020." + % type(self).__name__, + DeprecationWarning) return stringifier_class_getter()(*stringify_mapper_args) -- GitLab