|
From: Robert W. B. <rb...@di...> - 2001-04-07 21:26:15
|
Hi all,
I recently ran into another subtle differenct between CPython and
Jython that I was curious about. It concerns the "raise"
statement, and it's behavior when the first expression is an
instance object.
2.1a1 documentation says, "If the first expression is an instance object,
the second expression must be None."
In CPython example we see:
>>> import exceptions
>>> excpt = exceptions.TypeError()
>>> raise excpt, "Something not None"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: instance exception may not have a separate value
Currently in Jython we see:
>>> import exceptions
>>> excpt = exceptions.TypeError()
>>> raise excpt, "Something not None"
Traceback (innermost last):
File "<console>", line 1, in ?
: Something not None
I was thinking that raising the TypeError is worthwile here. What
do others think?
If this is a good idea, here's unified diff (cvs diff below-
which one is preferred anyway?)
======================================================
--- .\Py.java Sat Apr 7 16:17:42 2001
+++ c:\windows\desktop\Py.java Sat Apr 7 16:10:44 2001
@@ -1029,6 +1029,14 @@
}
public static PyException makeException(PyObject type,
PyObject value) {
+ if (type instanceof PyInstance) {
+ if (value != Py.None) {
+ throw TypeError("instance exceptions may not have
" +
+ "a separate value");
+ } else {
+ return new PyException(type.__class__, type);
+ }
+ }
PyException exc = new PyException(type, value);
exc.instantiate();
return exc;
@@ -1037,6 +1045,16 @@
public static PyException makeException(PyObject type,
PyObject value,
PyObject traceback)
{
+ if (type instanceof PyInstance) {
+ if (value != Py.None) {
+ throw TypeError("instance exceptions may not have
" +
+ "a separate value");
+ } else {
+ type = type.__class__;
+ //return new PyException(type.__class__, type);
+ }
+ }
+
if (traceback == None)
return new PyException(type, value);
if (!(traceback instanceof PyTraceback))
- OR -
Index: Py.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v
retrieving revision 2.41
diff -r2.41 Py.java
1031a1032,1039
> if (type instanceof PyInstance) {
> if (value != Py.None) {
> throw TypeError("instance exceptions may not
have " +
> "a separate value");
> } else {
> return new PyException(type.__class__, type);
> }
> }
1039a1048,1057
> if (type instanceof PyInstance) {
> if (value != Py.None) {
> throw TypeError("instance exceptions may not
have " +
> "a separate value");
> } else {
> type = type.__class__;
> //return new PyException(type.__class__, type);
> }
> }
>
|