Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f394f56

Browse files
committed
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).
1 parent 49bb0e3 commit f394f56

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Lib/exceptions.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ def __init__(self, *args):
5858
def __str__(self):
5959
if self.args == None:
6060
return ''
61-
elif type(self.args) == type(''):
62-
return self.args
63-
else:
64-
return `self.args`
61+
else:
62+
return str(self.args)
6563

6664
def __getitem__(self, i):
6765
if type(self.args) == type(()):
@@ -72,12 +70,17 @@ def __getitem__(self, i):
7270
raise IndexError
7371

7472
class SyntaxError(StandardError):
75-
def __init__(self, msg, info):
73+
filename = lineno = offset = text = None
74+
def __init__(self, msg, info=None):
7675
self.msg = msg
77-
self.filename, self.lineno, self.offset, self.text = info
78-
76+
if info:
77+
self.args = msg
78+
else:
79+
self.args = (msg, info)
80+
if info:
81+
self.filename, self.lineno, self.offset, self.text = info
7982
def __str__(self):
80-
return msg
83+
return str(self.msg)
8184

8285

8386
class IOError(StandardError):

0 commit comments

Comments
 (0)