
Steven D'Aprano wrote:
I find it difficult to imagine a more meaningful distinction than that between syntax and semantics.
That may be so, but when specifying a programming language, there is often some flexibility as to whether language rules are considered part of the syntax or the semantics. An extreme example of this is the formalism used to specify Algol 68, where, believe it or not, things such as the fact that identifiers must be declared in an enclosing scope are expressed in the *grammar*. Strictly speaking, anything that makes a particular sequence of symbols not be a valid program, that could in principle be determined by static analysis, can be considered a syntactic issue. So classifying a TargetScopeError as a kind of SyntaxError isn't necessarily wrong. There's actually a precedent for this in Python already:
def f(): ... nonlocal x ... x = 5 ... File "<stdin>", line 2 SyntaxError: no binding for nonlocal 'x' found
We seem to be happy to use a plain SyntaxError for that, not even bothering with a subclass. So I'm inclined to agree that TargetScopeError is not necessary. -- Greg