Git Product home page Git Product logo

Comments (3)

tseaver avatar tseaver commented on September 4, 2024

Wondered if this had been fixed, but no:

$ .tox/py313/bin/python
Python 3.13.0b1 (main, May 18 2024, 09:26:33) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from zope.i18nmessageid import ZopeMessageFactory as _
>>> msgid = _('foo', mapping={})
>>> msgid.mapping['bar'] = 'baz'

from zope.i18nmessageid.

tseaver avatar tseaver commented on September 4, 2024

Fixing this in Python should just be:

--- a/src/zope/i18nmessageid/message.py
+++ b/src/zope/i18nmessageid/message.py
@@ -13,6 +13,8 @@
 ##############################################################################
 """I18n Messages and factories.
 """
+import types
+
 
 __docformat__ = "reStructuredText"
 _marker = object()
@@ -55,7 +57,7 @@ class Message(str):
         if default is not _marker:
             self.default = default
         if mapping is not _marker:
-            self.mapping = mapping
+            self.mapping = types.MappingProxyType(mapping)
         if msgid_plural is not _marker:
             self.msgid_plural = msgid_plural
         if default_plural is not _marker:

with the equivalent change in C:

--- a/src/zope/i18nmessageid/_zope_i18nmessageid_message.c
+++ b/src/zope/i18nmessageid/_zope_i18nmessageid_message.c
@@ -101,7 +101,7 @@ Message_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
     self->default_ = default_;
 
   if (mapping != NULL)
-    self->mapping = mapping;
+    self->mapping = PyDictProxy_New(mapping);
 
   if (value_plural != NULL)
     self->value_plural = value_plural;

However, the current py3x-pure environments will load the C extension unconditionally (#28), so only the pypy3 tests would actually exercise the pure-Python side.

from zope.i18nmessageid.

tseaver avatar tseaver commented on September 4, 2024

The fix will be more complicated:

  • Branch around a passed value of None for the mapping (a dumb usecase, but tests do it).
  • Handle pickling / unpickling of the mappingproxy.

from zope.i18nmessageid.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.