On May 10, 2020, at 21:51, Christopher Barker <python...@gmail.com> wrote: > > > On Sun, May 10, 2020 at 9:36 PM Andrew Barnert <abarn...@yahoo.com> wrote: > >> However, there is one potential problem with the property I hadn’t thought >> of until just now: I think people will understand that mylist.view[2:] is >> not mutable, but will they understand that mystr.view[2:] is not a string? >> I’m pretty sure that isn’t a problem for seqview(mystr)[2:], but I’m not >> sure about mystr.view[2:]. > > One more issue around the whole "a string is sequence of strings" thing :-) > Of course, it *could* be a string -- not much difference with immutables. > Though I suppose if you took a large slice of a large string, you probably > don't want the copy. But what *would* you want to do with it.
That “string is a sequence of strings” issue, plus the “nothing can duck type as a string“ issue. Here’s an example that I can write in, say, Swift or Rust or even C++, but not in Python: I mmap a giant mailbox file, and I can treat that as a string without copying it anywhere. I split it into a string for each message—I don’t want to copy them all into a list of strings, and ideally I don’t even want to copy one at a time into an iterator or strings because some of them can be pretty huge; I want a list or iterator of views into substrings of the mmap. (This isn’t actually a great example, because even with substring views, the mmap can’t be used as a str in the first place, but it has the virtue of being a real example of code I’ve actually written.) > but if you had a view of a slice, and it was a proper view, it might be > pretty poky for many string operations, so probably just as well not to have > them. I think in general people will expect that a slice view on a sequence acts like “some kind of sequence”, not like the same kind they’re viewing—again, they won’t be surprised if you can’t insert into a slice of a list. It’s only with str that I’m worried they might expect more than we can provide, which sucks because str is the one place we _couldn’t_ provide it even if we wanted to. But maybe I’m wrong and people won’t have this assumption, or will be easily cured of it.
_______________________________________________ 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/CMHJKKVH2TQLED2W3KICEIQY43SBX27S/ Code of Conduct: http://python.org/psf/codeofconduct/