[Python-ideas] add an additional dataclasses.asdict option for non-dataclasses

Jeff Allen ja.py at farowl.co.uk
Sat May 11 06:31:19 EDT 2019


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190511/9acb8b10/attachment.html>


More information about the Python-ideas mailing list