Author Mark.Shannon
Recipients Mark.Shannon, ammar2, serhiy.storchaka
Date 2021-01-04.14:31:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609770680.79.0.959405453476.issue42739@roundup.psfhosted.org>
In-reply-to
Content
dis is able to handle code with no line numbers.

>>> def f(): pass
... 
>>> co = f.__code__.replace(co_linetable=b'\xff')
>>> list(co.co_lines())
[]
>>> import dis
>>> dis.dis(co)
          0 LOAD_CONST               0 (None)
          2 RETURN_VALUE

The problem with the example Serhiy gives is that the line number table does not end in a sentinel value.

You shouldn't be creating code objects unless you really know what you are doing. I.e. never.

For manually created code objects that don't respect the invariants, any behavior is acceptable IMO.
History
Date User Action Args
2021-01-04 14:31:20Mark.Shannonsetrecipients: + Mark.Shannon, serhiy.storchaka, ammar2
2021-01-04 14:31:20Mark.Shannonsetmessageid: <1609770680.79.0.959405453476.issue42739@roundup.psfhosted.org>
2021-01-04 14:31:20Mark.Shannonlinkissue42739 messages
2021-01-04 14:31:20Mark.Shannoncreate