On Wed, 9 Dec 2020 at 09:27, Mathew Elman <mathew.el...@ocado.com> wrote:
> I agree that if you are using them as iterables, then the type is usually > not important because you are treating their type as just iter-able. The > lazy iterable would more or less just be the same as passing in > `iter(sequence)`. > > This is for other use cases where the use of the object is specific to the > type, e.g. a case where in the outer scope you construct a list and mutate > it but when it is passed to an inner scope, you want to enforce that it can > be accessed but not mutated. Likewise if lazy built in types were > implemented in python then getting a slice of a sequence could also be done > lazily, whereas my understanding at the moment is that it has to create a > whole new sequence. > If you need this for annotations/typing alone, can't you just use `typing.cast` in the inner scope? (or before calling it for that matter) Anyway, mypy at least wil error if you annotate the inner scope as a "Sequence" (in contrast with MutableSequence), and will error if you try to change the Sequence - and it stlll remain compatible with incoming "MutableSequences". For the cases it does not cover, there is still "cast" - and it feels _a lot_ simpler than having actual runtime lazy objetcs as primitives in the language. > _______________________________________________ > 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/ZQIXX5632QT7QH5YCZGTTLPJ5ZQF7XOH/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/IWY3I4ZTPT2ZV7XFMGGSGOWHT3UOXA53/ Code of Conduct: http://python.org/psf/codeofconduct/