<div dir="ltr"> <iframe style="padding: 0px; position: absolute; top: 0px; left: 0px; width: 988px; height: 188px; visibility: hidden;" frameborder="0"></iframe><br>On Tuesday, July 19, 2016 at 7:41:38 PM UTC+5:30, Neil Girdhar wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jul 19, 2016 at 8:18 AM Rustom Mody  wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>On Tuesday, July 19, 2016 at 5:06:17 PM UTC+5:30, Neil Girdhar wrote:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"></div></div></blockquote></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jul 19, 2016 at 7:21 AM Steven D'Aprano wrote:<br></div></div></div></blockquote></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jul 18, 2016 at 10:29:34PM -0700, Rustom Mody wrote:<br>
<br></blockquote></div></div></blockquote></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> IOW<br>
> 1. The lexer is internally (evidently from the error message) so<br>
> ASCII-oriented that any “unicode-junk” just defaults out to identifiers<br>
> (presumably comments are dealt with earlier) and then if that lexing action<br>
> fails it mistakenly pinpoints a wrong *identifier* rather than just an<br>
> impermissible character like python 2<br>
<br>
You seem to be jumping to a rather large conclusion here. Even if you<br>
are right that the lexer considers all otherwise-unexpected characters<br>
to be part of an identifier, why is that a problem?<br></blockquote></div></div></blockquote></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>It's a problem because those characters could never be part of an identifier.  So it seems like a bug.</div></div></div></blockquote></div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"></div></div></blockquote><div><br>An armchair-design solution would say: We should give the most appropriate answer for every possible unicode character category<br>This would need to take all the Unicode character-categories and Python lexical-categories and 'cross-product' them — a humongous task to little advantage<br></div></div></blockquote><div><br></div></div><div dir="ltr"><div class="gmail_quote"><div>I don't see why this is a "humongous task".  Anyway, your solution boils down to the simplest fix in the lexer which is to block some characters from matching any category, does it not?</div></div></div></div></blockquote><div><br>Block? Not sure what you mean… Nothing should change (in the simplest solution at least) apart from better error messages<br>My suggested solution involved this:<br>Currently the lexer — basically an automaton — reveals which state its in when it throws error involving "identifier"<br>Suggested change: <br><br>if in_ident_state:<br>  if current_char is allowable as ident_char:<br>     continue as before<br>  elif current_char is ASCII:<br>     Usual error<br>  else:<br>     throw error eliding the "in_ident state"<br>else:<br>  as is...<br><br>BTW after last post I tried some things and found other unsatisfactory (to me) behavior in this area; to wit:<br><br> >>> x = 0o19<br>  File "<stdin>", line 1<br>    x = 0o19<br>           ^<br>SyntaxError: invalid syntax<br><br>Of course the 9 cannot come in an octal constant but "Syntax Error"??<br>Seems a little over general<br><br>My preferred fix:<br>make a LexicalError sub exception to SyntaxError<br><br>Rest should follow for both<br><br>Disclaimer: I am a teacher and having a LexicalError category makes it nice to explain some core concepts<br>However I understand there are obviously other more pressing priorities than to make python superlative as a CS-teaching language :-) <br></div></div>