Message 325691 - Python tracker

Message325691

Author izbyshev
Recipients berker.peksag, izbyshev, serhiy.storchaka
Date 2018-09-18.22:49:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537310945.11.0.956365154283.issue34729@psf.upfronthosting.co.za>
In-reply-to
Content
The compressor/decompressor classes from bz2 and lzma modules rely on __init__() for initialization, but it is not guaranteed to be called. Method calls on an uninitialized object crash:

>>> from bz2 import BZ2Compressor as C
>>> c = C.__new__(C)
>>> c.compress(b'')
Segmentation fault (core dumped)

I see two ways to fix this:

1) Move some initialization (notably, for "lock" field) to __new__() and add initialization checks to other methods. This should be backwards-compatible.

2) Move all initialization to __new__(). Since compressor/decompressor classes are not subclassable, it'll break only code than repeatedly calls __init__() on the same object. The simplicity of the fix might outweigh the necessity to support such code.
(However, in 2.7, classes in bz2 *are* subclassable; lzma is not present in 2.7).

Which way is more preferable?
History
Date User Action Args
2018-09-18 22:49:05izbyshevsetrecipients: + izbyshev, berker.peksag, serhiy.storchaka
2018-09-18 22:49:05izbyshevsetmessageid: <1537310945.11.0.956365154283.issue34729@psf.upfronthosting.co.za>
2018-09-18 22:49:05izbyshevlinkissue34729 messages
2018-09-18 22:49:04izbyshevcreate