This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: dis.dis raises IndexError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: elazar, ronaldoussoren, serhiy.storchaka
Priority: normal Keywords:

Created on 2013-05-28 02:08 by elazar, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg190169 - (view) Author: Elazar Gershuni (elazar) * Date: 2013-05-28 02:08
>>> dis.dis('pass')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dis.py", line 45, in dis
    disassemble_string(x)
  File "/usr/lib/python2.7/dis.py", line 112, in disassemble_string
    labels = findlabels(code)
  File "/usr/lib/python2.7/dis.py", line 166, in findlabels
    oparg = ord(code[i]) + ord(code[i+1])*256
IndexError: string index out of range

it happens for any string.
msg190170 - (view) Author: Elazar Gershuni (elazar) * Date: 2013-05-28 02:12
it happens that: (code, i) == ('pass', 4)
msg190176 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 06:32
AFAIK dis.dis only decompiles bytecode in python 2, as is mentioned in the documentation at <http://docs.python.org/2/library/dis.html?highlight=dis#dis.dis>.  In Python 3 dis.dis can compile a string with Python source to bytecode and decompile that (see <http://docs.python.org/3/library/dis.html?highlight=dis#dis.dis>).

Thus this is IMHO not a bug.
msg190179 - (view) Author: Elazar Gershuni (elazar) * Date: 2013-05-28 08:28
Is it standard procedure to raise an unrelated exception in when an invalid parameter is passed? I did not encounter any other library function that behaves like this. Especially taking the fact that this is the normal usage in python3. 

How do I supposed to *know* this is not a bug? I can't find similar behavior in other library functions. An IndexError and a traceback *inside the library* does not help.
msg190180 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 08:36
On 28 May, 2013, at 10:28, Elazar Gershuni <report@bugs.python.org> wrote:

> 
> Elazar Gershuni added the comment:
> 
> Is it standard procedure to raise an unrelated exception in when an invalid parameter is passed? I did not encounter any other library function that behaves like this. Especially taking the fact that this is the normal usage in python3. 

This is not the normal usage in python3, but one of the usecases supported in python3.  In python3 compiled code is a byte string and source code is a regular (unicode) string, which means the two can easily be recognized, while in python2 both are 'str' strings.

> 
> How do I supposed to *know* this is not a bug?

By reading the documentation? 

> I can't find similar behavior in other library functions. An IndexError and a traceback *inside the library* does not help.

Other library functions can also raise fairly obscure exceptions when you pass in bad data, as an example of this "os.path.join(None, 'a')" raises AttributeError.
msg190181 - (view) Author: Elazar Gershuni (elazar) * Date: 2013-05-28 08:43
If you pass 'None' for `path`, then "'NoneType' object has no attribute 'endswith'" is not as nearly as obscure.

But if you insist not to fix it, and don't mind to leave another arbitrary inconsistency between python2 and python3 obscured, I have nothing more to say - you can close it if you want.
msg190185 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-05-28 09:55
Seconded Ronald. It's not a bug.
msg190186 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 09:56
The automatic compilation of source code cannot be added to the 2.7 version of the dis module because that would be a new feature and we don't add new features in bugfix releases.  The feature was added to Python 3.x in issue #6507, and was first included in the 3.2 feature release.
History
Date User Action Args
2022-04-11 14:57:46adminsetgithub: 62277
2013-05-28 09:56:55ronaldoussorensetmessages: + msg190186
2013-05-28 09:55:27serhiy.storchakasetstatus: open -> closed

type: compile error -> behavior
title: dis.dis throws IndexError -> dis.dis raises IndexError
nosy: + serhiy.storchaka

messages: + msg190185
resolution: not a bug
stage: resolved
2013-05-28 08:43:12elazarsetmessages: + msg190181
2013-05-28 08:36:23ronaldoussorensetmessages: + msg190180
title: dis.dis raises IndexError -> dis.dis throws IndexError
2013-05-28 08:33:36elazarsettitle: dis.dis throws IndexError -> dis.dis raises IndexError
2013-05-28 08:28:50elazarsetmessages: + msg190179
2013-05-28 06:32:52ronaldoussorensetnosy: + ronaldoussoren
messages: + msg190176
2013-05-28 02:12:55elazarsetmessages: + msg190170
2013-05-28 02:08:54elazarcreate