On 2025-05-11 12:36:31 +0200, Left Right via Python-list wrote:
> Then it just means that the grammar lies.

No, because the parser accepts the sequence. And it produces exactly
what the description says.

The program

#!/usr/bin/python3

print("start")
for i in range(3):
    print("\copy")
print("end")

is valid and prints

start
\copy
\copy
\copy
end

to stdout, as you would expect from reading the docs.

But in addition to that it also prints the *warning* (not error, that's
a difference)

/home/hjp/tmp/./foo:5: SyntaxWarning: invalid escape sequence '\c'
  print("\copy")

to stderr (this is also documented).

One can quibble over the exact wording of the warning ("unrecognized"
would be more in line with the documentation than "invalid"), but there
are reasons for the warning.


> The two claims are mutually exclusive, so either one is a lie or the
> other or both.

No they are not. The grammar says that the program will compile and run,
which it does. The warning tells you that this probably wasn't a good
idea.

Warnings about stuff that is technically correct aren't unusual.
For example, in C something like 

#v+
int a = 5, b = 3;
if (a = b) {
    printf("a = %d\n", a);
}
#v-

is totally legal (and will print "a = 3"). However, most compilers will
warn about this because it is very likely that the programmer wanted to
write «if (a == b) ...».

> My comment was more of an irony really. It's plenty obvious that the
> grammar is a lie. The reason is that it's tedious to put the actual
> intender rules into the grammar, and so whoever wrote the grammar
> decided to cut corners. But, the grammar is supposed to be the
> authoritative source for how the language is parsed,

Which it is.

> that's why even though it's clear that the grammar is a lie, blaming
> whoever doesn't follow it makes it ironic.
> 
> In other words, the grammar author didn't put enough effort into
> making grammar actually work,

But the grammar *does* describe how it actually works. You *can* write
any character after a backslash, and your programm will compile and run.

It is likely that in some future version of Python that will not be the
case any more. *Then* the grammar must be changed. Until then the
documentation should match the current implementation and not something
which may or may not be implemented at some point in the future.

> but seeing how many other things are done in Python, this is not an
> exception. It would've been strange to have it done properly when
> "properly" means doing copious amounts of tedious work.

As usual you're making up your lack of knowledge with an abundance of
opinion.

        hjp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | h...@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment: signature.asc
Description: PGP signature

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to