ext Marcelo Lira wrote:

I've put my fears aside and started working on a PSEP. It isn't good
enough (even as a draft) to submit but I will talk about it anyway.

No worry - the ideas should be discussed on this list before submitting the pre-PSEPs anyway. :-p

It started as a proposal to change the way the QFile::open method is
used, but expanded to describe changes to all I/O operations.
The QFile::open method returns a boolean indicating the success or
failure of the I/O operation. In case of failure the user must call
QFile::error method to know what happened. Human readable information
is available through the inherited QIODevice::errorString method.

Compare this to opening a file with Python regular functions:

try:
    fd = open('/tmp/file.txt', 'r')
except IOError:
    ...

With the changes proposed on the PSEP we would use the QFile bindings this way:

try:
    fd = QFile('/tmp/file.txt')
    fd.open(QFile.ReadOnly | QFile.Text)
except IOError:
    ...

The code above is definitely more readable than the regular PySide code (your own example ;-)):

            fd = QFile('/tmp/file.txt')
            if fd.open(QFile.ReadOnly | QFile.Text):
                contents = fd.readAll()
            else:
                ...

However, what would this mean in practice? Modify all classes inherited from QIODevice to have their methods throw exceptions? How about any other methods in other Qt classes? I'm just worried it might become confusing if only some PySide class methods throw exceptions but not all.

Also a couple notes as food for thought (I don't necessarily propose these ideas but they could be discussed):

- Would it be possible to use QFile and Python file object interchangeably?

- Is there any use for instantiated but unopened QFile objects? Couldn't we open the file at the instantiation time?

The information contained in the exception could be gathered from
QFile::error and QIODevice::errorString.
Other candidates are QIODevice::read and QIODevice::write.

Shouldn't the error information be included in the exception itself?

Cheers,

ma.

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to