[Python-Dev] more SyntaxError subclasses!

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Wed, 12 Jul 2000 17:43:45 +0200

here are a bunch of other syntax error subclasses that
might be useful:

    class StatementError(SyntaxError):
        "you cannot use this statement here"
    class AssignmentError(StatementError):
        "you cannot assign to this target"
    class CompilerError(SyntaxError):
        "sorry, this is a compiler restriction, not really a language =
    class LimitError(CompilerError):
        "exceeded compiler limit"
    class TokenError(SyntaxError):
        "you cannot use this token here"
    class FunctionError(SyntaxError):
        "there's something wrong with this function/method declaration"
    class ArgumentError(FunctionError):
        "the argument declaration isn't correct"

here's how they're used in the current interpreter (before
the TabError/IndentationError patches):
    ArgumentError: "duplicate keyword argument"
    ArgumentError: "keyword can't be an expression"
    ArgumentError: "non-default argument follows default argument"
    ArgumentError: "non-keyword arg after keyword arg"
    AssignmentError: "can't assign to ()"
    AssignmentError: "can't assign to []"
    AssignmentError: "can't assign to function call"
    AssignmentError: "can't assign to lambda"
    AssignmentError: "can't assign to literal"
    AssignmentError: "can't assign to operator"
    LimitError: "expression too long"
    LimitError: "more than 255 arguments"
    StatementError: "'break' outside loop"
    StatementError: "'continue' not properly in loop"
    StatementError: "'return' outside function"
    StatementError: "default 'except:' must be last"
    StatementError: "name is local and global"
    SyntaxError: "invalid syntax"
    SyntaxError: "unexpected EOF while parsing"
    SyntaxError: "unknown parsing error"
    TabError: "inconsistent use of tabs and spaces in indentation"
    TokenError: "invalid token"


(I'm extra interested in arguments from people who think TabError
and IndentationError is a good idea, but that this one sucks.  I'm
not sure I want to hear from people who thinks that this one is a
great idea ;-)


on a more serious note, I think it would be great to add a distinct
attribute to the SyntaxError instance (an error number, most likely).
this could be used by an IDE to provide concise info without having
to parse the error message.

I'll post a more complete proposal later...

cheers /F