From c260a76e063780addb908c253f485aceeae4c6c3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 20 Feb 2016 13:35:40 +0100 Subject: [PATCH] Add fallback for interpreters which do not support __slots__ for str subclasses. Affects CPython 2.x, but neither CPython 3.x or Pypy. Incompatibility introduced in 38e7589ff3252a43aef3927f3b6c965788812b8a. --- src/i18n.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/i18n.py b/src/i18n.py index eb7150bd1..4eaf00c24 100644 --- a/src/i18n.py +++ b/src/i18n.py @@ -350,10 +350,19 @@ class InternationalizedFunction: def __call__(self, *args, **kwargs): return self._origin(*args, **kwargs) -class InternationalizedString(str): - """Simple subclass to str, that allow to add attributes. Also used to - know if a string is already localized""" - __slots__ = ('_original', '_internationalizer') +try: + class InternationalizedString(str): + """Simple subclass to str, that allow to add attributes. Also used to + know if a string is already localized""" + __slots__ = ('_original', '_internationalizer') +except TypeError: + # Fallback for CPython 2.x: + # TypeError: Error when calling the metaclass bases + # nonempty __slots__ not supported for subtype of 'str' + class InternationalizedString(str): + """Simple subclass to str, that allow to add attributes. Also used to + know if a string is already localized""" + pass def internationalizeDocstring(obj): """Decorates functions and internationalize their docstring.