You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
some methods of uninitialized io.IncrementalNewlineDecoder objects raise SystemError #75899
Given an uninitialized IncrementalNewlineDecoder:
uninitialized = io.IncrementalNewlineDecoder.__new__(io.IncrementalNewlineDecoder)
each of the following calls would raise a SystemError ('null argument to
internal routine'):
uninitialized.getstate()
uninitialized.setstate((b'foo', 0))
uninitialized.reset()
In contrast, the following call would raise a ValueError
('IncrementalNewlineDecoder.__init__ not called'):
uninitialized.decode(b'bar')
ISTM that getstate(), setstate(), and reset() should have the same behavior as
decode(). (Though i think that including the actual type name in the error
message would be better, as it could be a subclass of IncrementalNewlineDecoder).
There is other issues with IncrementalNewlineDecoder.__init__ -- it leaks references when called repeatedly.
The simplest solution of both issues will be moving the initialization to the new method. But this class looks designed for subclassing, and this can break subclasses that change arguments before passing them to the superclass' constructor.
orenmn commented on Oct 7, 2017
orenmnmannequin
MannequinAuthor
More actions
With regard to refleaks in __init__() methods, i started looking for similar refleaks
in the codebase, and hope to open an issue to fix them soon.
The patch for this issue had some outstanding questions/changes to be made before being merged, but now a new PR needs to be opened to replace the original one. Anyone who is interested can pick this up, but please only open one PR for this and please also credit the original author as per the dev guide. Thank you!
Activity
orenmn commentedon Oct 6, 2017
Given an uninitialized IncrementalNewlineDecoder:
uninitialized = io.IncrementalNewlineDecoder.__new__(io.IncrementalNewlineDecoder)
each of the following calls would raise a SystemError ('null argument to
internal routine'):
uninitialized.getstate()
uninitialized.setstate((b'foo', 0))
uninitialized.reset()
In contrast, the following call would raise a ValueError
('IncrementalNewlineDecoder.__init__ not called'):
uninitialized.decode(b'bar')
ISTM that getstate(), setstate(), and reset() should have the same behavior as
decode(). (Though i think that including the actual type name in the error
message would be better, as it could be a subclass of IncrementalNewlineDecoder).
serhiy-storchaka commentedon Oct 6, 2017
Is IncrementalNewlineDecoder subclassable?
orenmn commentedon Oct 6, 2017
Yes, although i don't know if there are usecases for that.
serhiy-storchaka commentedon Oct 6, 2017
There is other issues with IncrementalNewlineDecoder.__init__ -- it leaks references when called repeatedly.
The simplest solution of both issues will be moving the initialization to the new method. But this class looks designed for subclassing, and this can break subclasses that change arguments before passing them to the superclass' constructor.
orenmn commentedon Oct 7, 2017
With regard to refleaks in __init__() methods, i started looking for similar refleaks
in the codebase, and hope to open an issue to fix them soon.
csabella commentedon Feb 8, 2020
The patch for this issue had some outstanding questions/changes to be made before being merged, but now a new PR needs to be opened to replace the original one. Anyone who is interested can pick this up, but please only open one PR for this and please also credit the original author as per the dev guide. Thank you!