Re:Python 3.12.0 is to remove long-deprecated items
by derefr on Wednesday November 16, 2022 @03:36PM
(#33630143)
I don't believe that the problem was that "having two forms of print is nonoptimal"; I believe the point was instead to remove a parsing ambiguity, which in turn allowed a whole class of errors to be caught at load time that previously weren't; and allowed the syntax to be extended in other new ways that previously couldn't have been encoded as parse rules due to the ambiguity.
While the Python3 lexer is specifically hacked up to recognize the lexer-token for 'print' and to emit a token that triggers a special error-handling path in the parser if you then go on to make a syntax error per the newer uniform syntax, it doesn't actually know what you were trying to print. (That'd require a successful parse!) If the Python3 parser tried to do the compatible thing, that'd require ditching the uniform syntax altogether, and going back to the ambiguous parser.
It's a bit like Error Correcting Codes — the uniform Python3 parser knows enough to know that you did something wrong, and is provided by the lexer enough context to guess what kind of failure it was; but it doesn't have enough information to do the right thing, because that's a strictly-greater amount of information.
While the Python3 lexer is specifically hacked up to recognize the lexer-token for 'print' and to emit a token that triggers a special error-handling path in the parser if you then go on to make a syntax error per the newer uniform syntax, it doesn't actually know what you were trying to print. (That'd require a successful parse!) If the Python3 parser tried to do the compatible thing, that'd require ditching the uniform syntax altogether, and going back to the ambiguous parser.
It's a bit like Error Correcting Codes — the uniform Python3 parser knows enough to know that you did something wrong, and is provided by the lexer enough context to guess what kind of failure it was; but it doesn't have enough information to do the right thing, because that's a strictly-greater amount of information.