I am not sure if this has been suggested before, so my apologies if it has.

I would like to propose adding lazy types for casting builtins in a lazy 
fashion. e.g. `lazy_tuple` which creates a reference to the source iterable and 
a morally immutable sequence but only populates the tupular container when it 
or the source is used.

Note that if the original object is not a built-in, will not be used after 
casting  _or_ is immutable, this is trivial to implement. The difficulty arises 
when this it not the case, since the lazy object needs to also freeze any 
values that are mutated in the original to avoid side-effects.

An alternative to adding lazy types / lazy type casting (making it possible to 
implement these oneself) would be to add method call hooks to python, since 
this would allow having a "freeze value" callback hooked into the __setitem__ 
and __getitem__ methods.  Hooks may be a more useful solution for wider use 
cases as well.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SDAUO33DVPISBFQ52M2N4WEWPLJ4UDIS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to