The following printing ASCII characters are not used in Python. Their occurrence outside string literals and comments is an unconditional error:
$ ? `
I tried your code with the other symbols, and I have the same result you had. Anyway, if you try to run A $ B, you get a SyntaxError, as stated in the docs.
(Side note: If you want a more readable display of the token type, you can use tokenizer.tok_name to translate them to strings - for example, tokenizer.tok_name[55] == 'OP')
This is interesting. The first place I’d go for this - since it’s a change between 3.11 and 3.12 - is the What’s New for 3.12. And the tokenizer module IS mentioned:
It’s worth noting that the module itself carries a warning:
It’s not meant to be used on something that’s invalid. This is a bit surprising, a bit confusing. But, it seems the module doesn’t guarantee anything about how it behaves on illegal code.
Thank you very much for your advice and the links, @Rosuav and @Lucas_Malor.
I forgot to check “What’s new in Python 3.12”.
I understand that this is not a bug but an intended minor change and why the warning exists:
I believe 3.12 is when the new PEG parser was introduced. It operates differently from the previous one and some error detection seems to have been moved to a different stage of processing.