diff options
author | Guido van Rossum <guido@python.org> | 1997-09-05 19:00:56 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-09-05 19:00:56 (GMT) |
commit | f394f56c2bda5a3055b1f08e17882dfa39bbdf34 (patch) | |
tree | b02c5900e933c73efd6919b7df24a4ca6ec93795 /Lib/exceptions.py | |
parent | 49bb0e32a03c056a42df5c8d90347db19d3cb2d4 (diff) | |
download | cpython-f394f56c2bda5a3055b1f08e17882dfa39bbdf34.zip cpython-f394f56c2bda5a3055b1f08e17882dfa39bbdf34.tar.gz cpython-f394f56c2bda5a3055b1f08e17882dfa39bbdf34.tar.bz2 |
Made the 'info' argument to SyntaxError optional, so phase-2 syntax
errors are handled (these gave ``TypeError: not enough arguments'').
Also changed its __str__() to correct a typo (missing self.) and
return str(self.msg) to ensure the result is always string.
Also changed the default __str__ to simply return str(self.args).
Diffstat (limited to 'Lib/exceptions.py')
-rw-r--r-- | Lib/exceptions.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/exceptions.py b/Lib/exceptions.py index 4b03969..37b9590 100644 --- a/Lib/exceptions.py +++ b/Lib/exceptions.py @@ -58,10 +58,8 @@ class StandardError: def __str__(self): if self.args == None: return '' - elif type(self.args) == type(''): - return self.args - else: - return `self.args` + else: + return str(self.args) def __getitem__(self, i): if type(self.args) == type(()): @@ -72,12 +70,17 @@ class StandardError: raise IndexError class SyntaxError(StandardError): - def __init__(self, msg, info): + filename = lineno = offset = text = None + def __init__(self, msg, info=None): self.msg = msg - self.filename, self.lineno, self.offset, self.text = info - + if info: + self.args = msg + else: + self.args = (msg, info) + if info: + self.filename, self.lineno, self.offset, self.text = info def __str__(self): - return msg + return str(self.msg) class IOError(StandardError): |