Skip to content

Commit d2e1114

Browse files
committed
[GR-23223] Make test_exception_hierarchy pass
PullRequest: graalpython/956
2 parents 7827c29 + 83868c2 commit d2e1114

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
*AttributesTest.test_blockingioerror
12
*AttributesTest.test_errno_translation
23
*AttributesTest.test_posix_error
34
*AttributesTest.test_windows_error
45
*ExplicitSubclassingTest.test_errno_mapping
56
*ExplicitSubclassingTest.test_init_kwdargs
7+
*ExplicitSubclassingTest.test_init_new_overridden
8+
*ExplicitSubclassingTest.test_init_overridden
9+
*ExplicitSubclassingTest.test_init_standalone
10+
*ExplicitSubclassingTest.test_new_kwdargs
11+
*ExplicitSubclassingTest.test_new_overridden
612
*HierarchyTest.test_builtin_errors
713
*HierarchyTest.test_errno_mapping
14+
*HierarchyTest.test_select_error
15+
*HierarchyTest.test_socket_errors
816
*HierarchyTest.test_try_except

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public enum PythonBuiltinClassType implements LazyPythonClass {
168168
ZLibError("error", "zlib"),
169169
LZMAError("LZMAError", "_lzma"),
170170
StructError("StructError", "_struct"),
171+
SocketGAIError("gaierror", "_socket"),
172+
SocketHError("herror", "_socket"),
173+
SocketTimeout("timeout", "_socket"),
171174

172175
// todo: all OS errors
173176

@@ -318,6 +321,9 @@ public final DynamicObject newInstance() {
318321
ZipImportError.base = ImportError;
319322
ZLibError.base = Exception;
320323
LZMAError.base = Exception;
324+
SocketGAIError.base = OSError;
325+
SocketHError.base = OSError;
326+
SocketTimeout.base = OSError;
321327

322328
ReferenceError.base = Exception;
323329
RuntimeError.base = Exception;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SelectModuleBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6767
import com.oracle.graal.python.nodes.util.CoerceToDoubleNode;
6868
import com.oracle.graal.python.nodes.util.CoerceToFileDescriptorNode;
69+
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6970
import com.oracle.graal.python.runtime.sequence.PSequence;
7071
import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage;
7172
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -80,6 +81,11 @@
8081

8182
@CoreFunctions(defineModule = "select")
8283
public class SelectModuleBuiltins extends PythonBuiltins {
84+
85+
public SelectModuleBuiltins() {
86+
builtinConstants.put("error", PythonErrorType.OSError);
87+
}
88+
8389
@Override
8490
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
8591
return SelectModuleBuiltinsFactory.getFactories();

graalpython/lib-graalpython/exceptions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,34 @@ def _oserror_use_init(subtype):
131131

132132
def _oserror_init(self, *arg):
133133
narg = len(arg)
134+
self.args = arg
134135
self.errno = None
135136
self.strerror = None
136137
self.filename = None
137138
self.filename2 = None
138139
if (2 <= narg and narg <= 5):
140+
self.args = arg[0:2]
139141
self.errno = arg[0]
140142
self.strerror = arg[1]
141143
if(narg >= 5):
142144
self.filename2 = arg[4]
143145
if(narg >= 3):
144-
self.filename = arg[2]
146+
if type(self) == BlockingIOError:
147+
try:
148+
self.characters_written = arg[2].__index__()
149+
except Exception:
150+
self.filename = arg[2]
151+
else:
152+
self.filename = arg[2]
145153

146154
def OSError__new__(subtype, *args, **kwds):
147155
newtype = subtype
148156
if (not _oserror_use_init(newtype) and len(args) > 1):
149157
myerrno = args[0]
150158
if (type(myerrno) is int and subtype is OSError and myerrno in _errnomap):
151159
newtype = _errnomap[myerrno]
152-
153-
self = BaseException.__new__(newtype, *args, **kwds)
160+
161+
self = BaseException.__new__(newtype)
154162
self.errno = self.strerror = self.filename = self.filename2 = None
155163
if (not _oserror_use_init(newtype)):
156164
_oserror_init(self, *args)

0 commit comments

Comments
 (0)