def __new__(cls, file, encoder=EliotJSONEncoder):
        if isinstance(file, IOBase) and not file.writable():
            raise RuntimeError("Given file {} is not writeable.")

        unicodeFile = False
        try:
            file.write(b"")
        except TypeError:
            unicodeFile = True

        if unicodeFile:
            # On Python 3 native json module outputs unicode:
            _dumps = pyjson.dumps
            _linebreak = "\n"
        else:
            _dumps = bytesjson.dumps
            _linebreak = b"\n"
        return PClass.__new__(
            cls, file=file, _dumps=_dumps, _linebreak=_linebreak, encoder=encoder
        )