diff options
author | Zuul <zuul@review.opendev.org> | 2020-05-27 15:52:20 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-05-27 15:52:20 +0000 |
commit | e4d1659c6efc2cf4e33e957215c6a457bed18672 (patch) | |
tree | 327ea257f63f0de6a4ba2e59d029395e28641e5e | |
parent | 433a2ceace2fa57522475e7a5321c255c7f256fe (diff) | |
parent | 93b140577518ce905c890f579104e8ecff030821 (diff) | |
download | oslo-i18n-e4d1659c6efc2cf4e33e957215c6a457bed18672.tar.gz |
Merge "Remove Message.translate"
-rw-r--r-- | oslo_i18n/_message.py | 35 | ||||
-rw-r--r-- | oslo_i18n/tests/test_message.py | 9 |
2 files changed, 0 insertions, 44 deletions
diff --git a/oslo_i18n/_message.py b/oslo_i18n/_message.py index ce31970..09ed69c 100644 --- a/oslo_i18n/_message.py +++ b/oslo_i18n/_message.py @@ -68,41 +68,6 @@ class Message(six.text_type): msg.has_plural_form = has_plural_form return msg - def translate(self, desired_locale=None): - """DEPRECATED: Use ``translation`` instead - - This is a compatibility shim to allow callers a chance to move away - from using this function, which shadows a built-in function from our - parent class. - """ - # We did a bad thing here. We shadowed the unicode built-in translate, - # which means there are circumstances where this function may be called - # with a desired_locale that is a non-string sequence or mapping type. - # This will not only result in incorrect behavior, it also fails - # because things like lists are not hashable, and we use the value in - # desired_locale as part of a dict key. If we see a non-string - # desired_locale, we know that the caller did not intend to call this - # form of translate and we should instead pass that along to the - # unicode implementation of translate. - # - # Unfortunately this doesn't entirely solve the problem as it would be - # possible for a caller to use a string as the mapping type and in that - # case we can't tell which version of translate they intended to call. - # That doesn't seem to be a common thing to do though. str.maketrans - # returns a dict, and that is probably the way most callers will create - # their mapping. - if (desired_locale is not None and - not isinstance(desired_locale, six.string_types)): - return super(Message, self).translate(desired_locale) - warnings.warn('Message.translate called with a string argument. ' - 'If your intent was to translate the message into ' - 'another language, please call Message.translation ' - 'instead. If your intent was to call "translate" as ' - 'defined by the str/unicode type, please use a dict or ' - 'list mapping instead. String mappings will not work ' - 'until this compatibility shim is removed.') - return self.translation(desired_locale) - def translation(self, desired_locale=None): """Translate this message to the desired locale. diff --git a/oslo_i18n/tests/test_message.py b/oslo_i18n/tests/test_message.py index 9e5fa04..346e854 100644 --- a/oslo_i18n/tests/test_message.py +++ b/oslo_i18n/tests/test_message.py @@ -633,15 +633,6 @@ class MessageTestCase(test_base.BaseTestCase): table[ord('c')] = 'd' self.assertEqual('bcd', msg.translate(table)) - @mock.patch('warnings.warn') - def test_translate_warning(self, mock_warn): - msg = _message.Message('a message') - msg.translate('es') - self.assertTrue(mock_warn.called, 'No warning found') - # Make sure it was our warning - self.assertIn('Message.translate called with a string argument.', - mock_warn.call_args[0][0]) - class TranslateMsgidTest(test_base.BaseTestCase): |