Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12243 > unrolled thread
| Started by | Arnaud Delobelle <arnodel@gmail.com> |
|---|---|
| First post | 2011-08-26 23:20 +0100 |
| Last post | 2011-08-27 08:00 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
The RAISE_VARARGS opcode in Python 3 Arnaud Delobelle <arnodel@gmail.com> - 2011-08-26 23:20 +0100
Re: The RAISE_VARARGS opcode in Python 3 Peter Otten <__peter__@web.de> - 2011-08-27 08:49 +0200
Re: The RAISE_VARARGS opcode in Python 3 Arnaud Delobelle <arnodel@gmail.com> - 2011-08-27 08:00 +0100
| From | Arnaud Delobelle <arnodel@gmail.com> |
|---|---|
| Date | 2011-08-26 23:20 +0100 |
| Subject | The RAISE_VARARGS opcode in Python 3 |
| Message-ID | <mailman.454.1314397241.27778.python-list@python.org> |
Hi all, Here is an extract from the dis module doc [1] """ RAISE_VARARGS(argc) Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS. """ OTOH, looking at PEP 3109: """ In Python 3, the grammar for raise statements will change from [2] raise_stmt: 'raise' [test [',' test [',' test]]] to raise_stmt: 'raise' [test] """ So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python 3, whereas it could be up to 3 in Python 2. Can anyone confirm that this is the case? In this case, I guess the dis docs need to be updated. Thank you, Arnaud [1] http://docs.python.org/py3k/library/dis.html#opcode-RAISE_VARARGS [2] http://www.python.org/dev/peps/pep-3109/#grammar-changes
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2011-08-27 08:49 +0200 |
| Message-ID | <j3a428$16b$1@solani.org> |
| In reply to | #12243 |
Arnaud Delobelle wrote:
> Here is an extract from the dis module doc [1]
>
> """
> RAISE_VARARGS(argc)
> Raises an exception. argc indicates the number of parameters to the
> raise statement, ranging from 0 to 3. The handler will find the
> traceback as TOS2, the parameter as TOS1, and the exception as TOS.
> """
>
> OTOH, looking at PEP 3109:
>
> """
> In Python 3, the grammar for raise statements will change from [2]
>
> raise_stmt: 'raise' [test [',' test [',' test]]]
> to
>
> raise_stmt: 'raise' [test]
> """
>
> So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python
> 3, whereas it could be up to 3 in Python 2.
It can be up to 2 in Python 3,
>>> help("raise")
The ``raise`` statement
***********************
raise_stmt ::= "raise" [expression ["from" expression]]
...
confirmed by a quick look into ceval.c:
TARGET(RAISE_VARARGS)
v = w = NULL;
switch (oparg) {
case 2:
v = POP(); /* cause */
case 1:
w = POP(); /* exc */
case 0: /* Fallthrough */
why = do_raise(w, v);
break;
default:
PyErr_SetString(PyExc_SystemError,
"bad RAISE_VARARGS oparg");
why = WHY_EXCEPTION;
break;
}
break;
> Can anyone confirm that
> this is the case? In this case, I guess the dis docs need to be
> updated.
Indeed.
[toc] | [prev] | [next] | [standalone]
| From | Arnaud Delobelle <arnodel@gmail.com> |
|---|---|
| Date | 2011-08-27 08:00 +0100 |
| Message-ID | <mailman.456.1314428436.27778.python-list@python.org> |
| In reply to | #12249 |
On 27 August 2011 07:49, Peter Otten <__peter__@web.de> wrote:
> Arnaud Delobelle wrote:
>
>> Here is an extract from the dis module doc [1]
>>
>> """
>> RAISE_VARARGS(argc)
>> Raises an exception. argc indicates the number of parameters to the
>> raise statement, ranging from 0 to 3. The handler will find the
>> traceback as TOS2, the parameter as TOS1, and the exception as TOS.
>> """
>>
>> OTOH, looking at PEP 3109:
>>
>> """
>> In Python 3, the grammar for raise statements will change from [2]
>>
>> raise_stmt: 'raise' [test [',' test [',' test]]]
>> to
>>
>> raise_stmt: 'raise' [test]
>> """
>>
>> So it seems that RAISE_VARARGS's argument can only be 0 or 1 in Python
>> 3, whereas it could be up to 3 in Python 2.
>
> It can be up to 2 in Python 3,
>
>>>> help("raise")
> The ``raise`` statement
> ***********************
>
> raise_stmt ::= "raise" [expression ["from" expression]]
> ...
>
> confirmed by a quick look into ceval.c:
>
> TARGET(RAISE_VARARGS)
> v = w = NULL;
> switch (oparg) {
> case 2:
> v = POP(); /* cause */
> case 1:
> w = POP(); /* exc */
> case 0: /* Fallthrough */
> why = do_raise(w, v);
> break;
> default:
> PyErr_SetString(PyExc_SystemError,
> "bad RAISE_VARARGS oparg");
> why = WHY_EXCEPTION;
> break;
> }
> break;
Thanks again, Peter! I'm out of Python practice, and I've forgotten
some things like help("keyword"). Also PEP 3109 does indeed mention
the raise .. from .. syntax in an example at the end.
--
Arnaud
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web