> While a partial object should reasonably never change, you could change it: >>>> from functools import partial >>>> p = partial(lambda *a, **kw: kw, 1, 2, spam='eggs') >>>> p() > {'spam': 'eggs'} >>>> p.keywords['spam'] = 'bacon' >>>> p() > {'spam': 'bacon'} >>>> > I realize touching p.keywords voids your warranty, but if we can stop people > from doing it, maybe we should (or at least put a warning in the > documentation, no?). So I'm thinking either we make an immutable/hashable > dict while we're at it, or store the keyword arguments as a tuple (which > guarantees immutability), and only convert them back to a dict when you want > to call the partial object (simpler, slower).
You're right. I think it is possible to stop people from modifying p.keywords. If p.keywords wouldn't be a dict, but a read-only proxy for that dict, that may solve this problem. I think that is possible, with PyDictProxy_New [1]. But I'm not certain if that is a good idea, it may have side effects I'm not aware of. Any thoughts about this? > Your thoughts? Should we continue this discussion at issue8699? I don't know, I'm new here... [1] http://docs.python.org/py3k/c-api/dict.html#PyDictProxy_New Thanks, Daniel Urban _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com