On 8/8/2019 7:28 PM, Barry Warsaw wrote:
On Aug 8, 2019, at 14:58, Steven D'Aprano <steve@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