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.

> The name is perfectly self-descriptive: TargetScopeError means that
> there's an error with the scope of the target. What else could it mean?

What’s the scope?  What’s *a* scope (in this context)?  What’s the target?  
Nothing about the exception name tells you that it’s a problem with the 
assignment expression you wrote.

> What's wrong with having to look up an unfamiliar exception by searching
> the interwebs? The first few times I hit KeyError, I had no idea what a
> "key" was (I was a beginner) and if I had internet access, I would have
> looked it up on the web. I didn't, so I looked it up in the book I was
> reading.

But remember that assignment expressions are a relatively advanced topic.  Once 
you learned what a key was — and you have to do that pretty early on in your 
Python experience — KeyError is perfectly descriptive.

So let’s imagine what the user experience would be like with a better named 
exception to see whether a subclass is worth it.  For now let’s call it 
AssignmentExpressionDisallowedError.  If you saw that it would definitely be 
more descriptive.  Is that valuable in the error output?  Is it still valuable 
when you have useful descriptive text?

> Please let's not use SyntaxError for something that's not an error
> with the syntax.

PEP 572 does propose TargetScopeError as a subclass of SyntaxError, so you’re 
getting a SyntaxError anyway.

-Barry

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
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/2AMSRRGEXFQOLIRVCUXRR7U6CM6EMTPJ/

Reply via email to