On Sun, Jan 16, 2022 at 11:41:52PM +1100, Chris Angelico wrote:
> On Sun, Jan 16, 2022 at 11:18 PM Steven D'Aprano <st...@pearwood.info> wrote:

> > Not to mention:
> >
> >     r(1, 2, 3)  # look up r, call it with parameters
> >     r[1, 2, 3]  # look up r, subscript it
> >     r"1, 2, 3"  # a string literal
> 
> Strings behave differently in many many ways. Are there any non-string
> types that differ?

There are plenty of non-string types which differ :-)

Differ in what way? I don't understand your question.

You were concerned that adding a prefix to a delimiter in the form of 
f{...} would be a bug magnet, but we have had prefixes on delimiters for 
30 years in the form of r"..." etc, and it hasn't been a problem.

I mean, sure, the occasional beginner might get confused and write

    len{mystring}

and if by some fluke they call f() rather than len() they will get a 
silent failure instead of a SyntaxError, but is this really a serious 
problem that is common enough to get labelled "a bug magnet"?

I've been coding in Python for two decades and I still occassionally 
mess up round and square brackets, especially late at night, and I won't 
tell you how often I write my dict displays with equal signs 
{key=value}, or misspell str.center.

And I still cringe about the time a few years back where my brain forgot 
that Python spells it "None" rather than "nil" like in Pascal, and I 
spent about an hour writing a ton of "if obj is nil"... tests.

Typos and brain farts happen.


> > Reading this makes my eyes bleed:
> >
> >     >>> <1, 2, 3> < <1, 2, 3, 4>
> >     True
> 
> Fair point, but I can't imagine people comparing two literals like
> that.

They don't have to be literals inside the brackets. Especially in the 
REPL, `{*a} < {*b}` is a quick way of testing that every element of a is 
an element of b.

[...]
> > Triple quoted strings say hello :-)
> 
> See above, strings are different, and people treat them differently.

Do they? How are they different? You have a start delimiter and an end 
delimiter.

The only difference I see is that with strings the delimiter is the 
same, instead of a distinct open and close delimiter. But that 
difference is surely not a reason to reject the use of a prefix.

"We can't use a prefix because the closing delimiter is different from 
the opening delimiter" does not follow.


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

Reply via email to