On Wed, Dec 09, 2020 at 12:05:17PM -0000, Mathew Elman wrote:
> Steven D'Aprano wrote:
> > On Tue, Dec 08, 2020 at 11:46:59AM -0000, Mathew Elman wrote:
> > > 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.
> > > What are your use-cases for this?
> > Does this include things like lazy_list, lazy_float,
> > lazy_bool, 
> > lazy_str, lazy_bytearray etc?
> 
> I would say yes, it should include these types as well. 

> The use case is for when you are casting between types a high number 
> of times to pass them around, especially into another type and back.

I would say, *don't do that*. If you have a list, and you pass it to 
another function after converting to a tuple, why would you take that 
tuple and convert back to a list when you already have a list?

For types like casting back and forth between float and int, there will 
be data loss.

Even if there is not, the overhead of creating a "lazy proxy" to the 
float is probably greater than just converting.


> > How do these hooks freeze the list?
> 
> they don't freeze the list, they freeze the values in the lazy_tuple 
> when the list is mutated, so when mutating the list, the values in the 
> tuple are set (if they have not been already), so that they aren't 
> also mutated in the lazy_tuple.

How is this supposed to work in practice? Where does the hook live? When 
is it called? What does it do?

How does the lazy tuple know that the list's setitem has been called?


-- 
Steve
_______________________________________________
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/AHVWVQZSC74R37ICARCHYIGBJTP54KCP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to