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 38e7589ff3.
This commit is contained in:
Valentin Lorentz 2016-02-20 13:35:40 +01:00
parent 15e387ea46
commit c260a76e06
1 changed files with 13 additions and 4 deletions

View File

@ -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.