On 8/8/2019 7:28 PM, Barry Warsaw wrote:
On Aug 8, 2019, at 14:58, Steven D'Aprano <st...@pearwood.info> wrote:

It's not a syntax error. There's nothing wrong with the syntax per-say:
we still have ``target := expression``. There's a problem with the
*semantics* not the syntax.

I’m not sure that distinction is meaningful though.  What you wrote is 
disallowed, so you have to change your code (i.e. syntax) to avoid the error.

I agree with Barry here. For all practical purposes, it's a syntax error. And if we had a more powerful parser, maybe it really would be a syntax error. See Guido's recent PEG parser articles (https://medium.com/@gvanrossum_83706/peg-parsers-7ed72462f97c) where he discusses raising SyntaxError after the parser is finished, in a subsequent pass. Is it really a syntax error if pgen doesn't object to it? In current CPython, the answer is yes.

But to the original point: I think the real reason to make this just a SyntaxError, and not a subclass (TargetScopeError) is this: would you ever catch TargetScopeError? If not, why would it need to be its own class? It should just be SyntaxError with a descriptive enough text that the user can figure out what's wrong.

I don't see anyone ever writing:

try:
    .. something ..
except TargetScopeError:
    .. handle this ..
except SyntaxError:
    .. handle this differently ..

Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/5AALXTK5JKZSFBDPVD2Y2ONE2JFEKDN7/

Reply via email to