Skip to content

Commit

Permalink
Make the Python implementation stop apptempting to pointlessly copy s…
Browse files Browse the repository at this point in the history
…trings and (somewhat pointedly) copy mappings, like the C implementation.
  • Loading branch information
jamadden committed Oct 19, 2018
1 parent 42699cc commit a2c0e41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/zope/i18nmessageid/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def __new__(cls, ustr, domain=_marker, default=_marker, mapping=_marker,
msgid_plural=_marker, default_plural=_marker, number=_marker):
self = six.text_type.__new__(cls, ustr)
if isinstance(ustr, self.__class__):
self.domain = ustr.domain[:] if ustr.domain else None
self.default = ustr.default[:] if ustr.default else None
self.mapping = ustr.mapping.copy() if ustr.mapping is not None else None
self.msgid_plural = ustr.msgid_plural[:] if ustr.msgid_plural else None
self.default_plural = ustr.default_plural[:] if ustr.default_plural else None
self.domain = ustr.domain
self.default = ustr.default
self.mapping = ustr.mapping
self.msgid_plural = ustr.msgid_plural
self.default_plural = ustr.default_plural
self.number = ustr.number
else:
self.domain = None
Expand Down
14 changes: 13 additions & 1 deletion src/zope/i18nmessageid/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def test_copy(self):
self.assertEqual(message.msgid_plural, 'testings')
self.assertEqual(message.default_plural, 'defaults')
self.assertEqual(message.number, 0)

# Besides just being equal, they maintain their identity
for attr in (
'domain',
'default',
'mapping',
'msgid_plural',
'default_plural',
'number',
):
self.assertIs(getattr(source, attr),
getattr(message, attr))

if self._TEST_READONLY:
self.assertTrue(message._readonly)

Expand Down Expand Up @@ -156,7 +169,6 @@ def test_copy_no_overrides(self):
self.assertIsNone(getattr(pref_msg, attr))
self.assertIsNone(getattr(copy, attr))


def test_domain_immutable(self):
message = self._makeOne('testing')
with self.assertRaises((TypeError, AttributeError)):
Expand Down

0 comments on commit a2c0e41

Please sign in to comment.