On Oct 27, 2019, at 05:49, Chris Angelico <ros...@gmail.com> wrote:

>> Given zero-based indexing, and the string:
>> 
>>    "abÇÐεф"
>> 
>> the index of "ф" better damn well be 5 rather than 8 (UTF-8), 10
>> (UTF-16) or 20 (UTF-32) or I'll be knocking on the API designer's door
>> with a pitchfork and a flaming torch *wink*
>> 
>> And returning <AbstractIndex object at 0xb7ce1bf0> is even worse.
>> 
> 
> And in response to the notion that you don't actually need the index,
> just a position marker... consider this:
> 
>  File "/home/rosuav/tmp/demo.py", line 1
>    print("Hello, world!')
>                         ^
> SyntaxError: EOL while scanning string literal

So if those 12 glyphs take 14 code units because you’re using Stephen’s string 
and it’s in NFKD, getting 14 and then indenting two spaces too many (as Python 
does today) is not just a good-enough best effort, but something we actually 
want to ensure at all costs by making sure you always deal in code unit indexes?

> Well, either that, or we need to make it so that " "*<AbstractIndex
> object at 0xb7ce1bf0> results in the correct number of spaces to
> indent it to that position. That ought to bring in plenty of
> pitchforks...

Would you still bring pitchforks for " " * StrIndex(chars=12, points=14, 
bytes=22)? 

If so, then you require code to spell it as " " * index.chars instead of " " * 
index.

It’s not like the namedtuple/structseq/dataclass/etc. repr is some innovative 
new idea nobody’s ever thought of to get a useful display, or like people can’t 
figure out how to get the index out of a regex match object. This is all simple 
stuff; I don’t get the incredulity that it could possibly be done. (Especially 
given that there are other languages that do exactly the same thing, like 
Swift, which ought to be proof that it’s not impossible.)

(Could it be done without breaking a whole ton of existing code? I strongly 
doubt it. But my whole argument for why we shouldn’t be trying to “fix” strings 
in “Python 4000” in the first place is that the right fix probably cannot be 
done in a way that’s remotely feasible for backward compatibility. So I hope 
you wouldn’t expect that something additional that I suggested could be 
considered only if that unfeasible fix were implemented would itself be 
feasible.)
_______________________________________________
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/X5B5SQ2RLRHMBPAZABRQ5TSRQ74JAXW5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to