Skip to content

Commit 56e06a9

Browse files
committed
i18n: Remove hacks for Python 2
1 parent 467fd54 commit 56e06a9

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/i18n.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def getLocalePath(name, localeName, extension):
117117
return '%s/%s.%s' % (directory, localeName, extension)
118118

119119
i18nClasses = weakref.WeakValueDictionary()
120-
internationalizedCommands = weakref.WeakValueDictionary()
120+
internationalizedCommands = weakref.WeakSet()
121121

122122
def reloadLocalesIfRequired():
123123
global currentLocale
@@ -132,7 +132,7 @@ def reloadLocales():
132132

133133
for pluginClass in i18nClasses.values():
134134
pluginClass.loadLocale()
135-
for command in list(internationalizedCommands.values()):
135+
for command in list(internationalizedCommands):
136136
internationalizeDocstring(command)
137137
utils.str._relocalizeFunctions(PluginInternationalization())
138138

@@ -331,19 +331,10 @@ def localizeFunction(self, name):
331331
return self._l10nFunctions[name]
332332

333333

334-
try:
335-
class InternationalizedString(str):
336-
"""Simple subclass to str, that allow to add attributes. Also used to
337-
know if a string is already localized"""
338-
__slots__ = ('_original', '_internationalizer')
339-
except TypeError:
340-
# Fallback for CPython 2.x:
341-
# TypeError: Error when calling the metaclass bases
342-
# nonempty __slots__ not supported for subtype of 'str'
343-
class InternationalizedString(str):
344-
"""Simple subclass to str, that allow to add attributes. Also used to
345-
know if a string is already localized"""
346-
pass
334+
class InternationalizedString(str):
335+
"""Simple subclass to str, that allow to add attributes. Also used to
336+
know if a string is already localized"""
337+
__slots__ = ('_original', '_internationalizer')
347338

348339

349340
def internationalizeDocstring(obj):
@@ -354,7 +345,7 @@ def internationalizeDocstring(obj):
354345
return obj
355346
plugin_module = sys.modules[obj.__module__]
356347
if '_' in plugin_module.__dict__:
357-
internationalizedCommands.update({hash(obj): obj})
348+
internationalizedCommands.add(obj)
358349
try:
359350
obj.__doc__ = plugin_module._.__call__(obj.__doc__)
360351
# We use _.__call__() instead of _() because of a pygettext warning.

0 commit comments

Comments
 (0)