Comments (3)
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.
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.
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)
- C extension not used in Python 3
- C/Python consitency: C doesn't convert `default` to unicode
- Fix process of reference count during GC HOT 1
- Set up Appveyor to build and upload Windows wheels to PyPI
- Regression in 4.3 Python impl: NoneType object is not subscriptable
- sdist on PyPI broken with new setuptools HOT 4
- Add support to release aarch64 wheels HOT 1
- Support PURE_PYTHON
- doc link 404 HOT 1
- 5.0.1: sphinx warnings `reference target not found` HOT 2
- Request for official support for Python >3.8 HOT 3
- 5.1.0 release is missing sdist (and non-Windows wheels) HOT 6
- six seems to be unused HOT 3
- Hacking documentation is outdated
- RFE: is it possible to start making github releases?🤔 HOT 2
- Python 'Message.__setattr__' implementation raises the wrong error for the '_readonly' case
- Docs build raises a Sphinx warning under 7.x, would break under 8.x
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zope.i18nmessageid.