diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index da651384be63d11723b349fdd6014924a89bab10..f1afc0f8d31494176e97b215c73fb9e8d6366152 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 88cf8f523490afac1153b621ffcabb1fb0f43855..0ca0a6d5d898008ee65a1c078eff90c670c8f7de 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)