Jul-20-2021, 08:45 PM
I think there is way too much code in
_zio.__init__()
and most of this code is not directly related to the instance being created. Only three attributes are set in this method, namely self.realname, self.tmpname, self.allfiles
. I think most of this method's code should be written in an external "factory" function named for example _new_io()
and the structure could bedef _new_io(name=None,mode='r',compresslevel=None,*, buffering=-1, compress=None, closefd=True, check=-1, encoding=None, errors=None, format=None, newline=None, tempname=False, ): ... zio = _zio(realname, tmpname, allfiles) ... return zio class _zio(io.IOBase): def __init__(self, realname, tmpname, allfiles): self.realname = realname self.tmpname = tmpname self.allfiles = allfiles ...
zopen()
and ztopen()
would invoke _new_io()
instead of _zio()
and the advantage is that the body of _new_io()
can now incorporate special cases where it returns something different from a _zio()
instance, perhaps another instance of io.IOBase()
.