On 11/05/2019 02:46, Christopher Barker wrote:
Though yeah, that’s the key question— how often is this useful???
I have wanted something similar to this in Jython. Java supplies a
battery of containers (with different performance and concurrency
characteristics) and we monkepatch onto them the methods of list, set or
dict according to their interface as java.util.List, Set or Map. This
works "slightly badly", because sometimes those Python types have
methods with the same name as one in the underlying container, but a
different meaning. E.g. list.pop() disgrees about which end.
I'd much rather have some kind of explicit wrapping or cast into their
Python type: I had imagined the wrapped object would identify and behave
as exactly that Python type (or ABC), however, it would be a *proxy* to
the original. Thus one obtains a "view" onto the original collection, or
looked at another way, a way to choose the implementation behind a
particular Python dict, set or list.
Several alternative ways of expressing this come to mind, but .asdict()
is one.
It's not always clear in this discussion whether a proxy is envisaged
(where a put() goes through to the original object, if allowed) or just
a way of constructing and filling a new dict. The latter would not fit
my imagined use.
Jeff
Jeff Allen
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/