Skip to content

Commit 1e2df9f

Browse files
committed
Add missing constructors to exception types
1 parent 2abe17a commit 1e2df9f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

graalpython/lib-graalpython/exceptions.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,71 @@ def StopIteration__value__set(self, arg):
8282

8383
StopIteration.value = property(fget=StopIteration__value__get, fset=StopIteration__value__set)
8484

85+
86+
def SyntaxError__init__(self, *args, **kwargs):
87+
BaseException.__init__(self, *args, **kwargs)
88+
self.msg = None
89+
self.filename = None
90+
self.lineno = None
91+
self.offset = None
92+
self.text = None
93+
self.print_file_and_line = None
94+
if len(args) > 0:
95+
self.msg = args[0]
96+
if len(args) == 2:
97+
info = tuple(args[1])
98+
if len(info) != 4:
99+
raise IndexError("tuple index out of range")
100+
self.filename = info[0]
101+
self.lineno = info[1]
102+
self.offset = info[2]
103+
self.text = info[3]
104+
105+
106+
SyntaxError.__init__ = SyntaxError__init__
107+
del SyntaxError__init__
108+
109+
110+
def UnicodeEncodeError__init__(self, encoding, object, start, end, reason):
111+
BaseException.__init__(self, encoding, object, start, end, reason)
112+
self.encoding = encoding
113+
self.object = object
114+
self.start = start
115+
self.end = end
116+
self.reason = reason
117+
118+
119+
UnicodeEncodeError.__init__ = UnicodeEncodeError__init__
120+
del UnicodeEncodeError__init__
121+
122+
123+
def UnicodeDecodeError__init__(self, encoding, object, start, end, reason):
124+
BaseException.__init__(self, encoding, object, start, end, reason)
125+
self.encoding = encoding
126+
if isinstance(object, bytes):
127+
self.object = object
128+
else:
129+
self.object = bytes(object)
130+
self.start = start
131+
self.end = end
132+
self.reason = reason
133+
134+
135+
UnicodeDecodeError.__init__ = UnicodeDecodeError__init__
136+
del UnicodeDecodeError__init__
137+
138+
139+
def UnicodeTranslateError__init__(self, object, start, end, reason):
140+
self.object = object
141+
self.start = start
142+
self.end = end
143+
self.reason = reason
144+
145+
146+
UnicodeTranslateError.__init__ = UnicodeTranslateError__init__
147+
del UnicodeTranslateError__init__
148+
149+
85150
# These errors are just an alias of OSError (i.e. 'EnvironmentError is OSError == True')
86151
EnvironmentError = OSError
87152
IOError = OSError

0 commit comments

Comments
 (0)