I guess you were mainly testing with Python 2. Python 3 on Linux does not raise any error either:
wrote 3 to a read-only file
should raise, opening a ro descriptor for writing
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
BTW in your test script you close the underlying file descriptor “fd” before giving the file object “fd2” a chance to flush or close, which is probably why you see no error. Though in Wine I see this, probably because file.write() does not return a value in Python 2:
properly raised TypeError('%d format: a number is required, not NoneType',)
What would be the reason for doing a mode check in fdopen()? Just to detect programmer errors if the wrong mode or file descriptor is given? |