Kaydet (Commit) f394f56c authored tarafından Guido van Rossum's avatar Guido van Rossum

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).
üst 49bb0e32
...@@ -58,10 +58,8 @@ class StandardError: ...@@ -58,10 +58,8 @@ class StandardError:
def __str__(self): def __str__(self):
if self.args == None: if self.args == None:
return '' return ''
elif type(self.args) == type(''): else:
return self.args return str(self.args)
else:
return `self.args`
def __getitem__(self, i): def __getitem__(self, i):
if type(self.args) == type(()): if type(self.args) == type(()):
...@@ -72,12 +70,17 @@ class StandardError: ...@@ -72,12 +70,17 @@ class StandardError:
raise IndexError raise IndexError
class SyntaxError(StandardError): class SyntaxError(StandardError):
def __init__(self, msg, info): filename = lineno = offset = text = None
def __init__(self, msg, info=None):
self.msg = msg 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): def __str__(self):
return msg return str(self.msg)
class IOError(StandardError): class IOError(StandardError):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment