classification
Title: io.open() is inconsistent re os.open()
Type: behavior Stage: resolved
Components: IO, Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, apalala, davbo, pitrou, python-dev
Priority: normal Keywords:

Created on 2012-07-04 02:55 by apalala, last changed 2012-07-06 17:03 by pitrou. This issue is now closed.

Messages (6)
msg164633 - (view) Author: Juancarlo Añez (apalala) Date: 2012-07-04 02:55
>>> import io
>>> d = io.open('.')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IsADirectoryError: [Errno 21] Is a directory: '.'
>>> 

>>> import os
>>> d = io.open(os.open('.',0))
>>> d
<_io.TextIOWrapper name=3 mode='r' encoding='UTF-8'>
>>>
msg164634 - (view) Author: Juancarlo Añez (apalala) Date: 2012-07-04 02:56
io.open() clearly doesn't care about opening directories as long as they are passed as os.open() file descriptors. Quite unexpected!
msg164655 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-04 17:55
Good catch indeed.
msg164664 - (view) Author: Juancarlo Añez (apalala) Date: 2012-07-04 23:00
Note that attempting subsequent operations on the returned object do raise IsADirectoryError.


>>> import io
>>> import os
>>> d = io.open(os.open('.',0))
>>> d.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IsADirectoryError: [Errno 21] Is a directory
>>>
msg164737 - (view) Author: Roundup Robot (python-dev) Date: 2012-07-06 17:02
New changeset 9cf9527358a5 by Antoine Pitrou in branch '3.2':
Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.
http://hg.python.org/cpython/rev/9cf9527358a5

New changeset 19bd61ed3b3b by Antoine Pitrou in branch 'default':
Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.
http://hg.python.org/cpython/rev/19bd61ed3b3b

New changeset d7040647d590 by Antoine Pitrou in branch '2.7':
Issue #15247: FileIO now raises an error when given a file descriptor pointing to a directory.
http://hg.python.org/cpython/rev/d7040647d590
msg164738 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-06 17:03
Thanks, the issue should be fixed now.
History
Date User Action Args
2012-07-06 17:03:35pitrousetstatus: open -> closed
resolution: fixed
messages: + msg164738

stage: needs patch -> resolved
2012-07-06 17:02:32python-devsetnosy: + python-dev
messages: + msg164737
2012-07-06 16:18:04davbosetnosy: + davbo
2012-07-04 23:00:02apalalasetmessages: + msg164664
2012-07-04 22:35:44Arfreversetnosy: + Arfrever
2012-07-04 17:55:22pitrousetversions: + Python 3.2
nosy: + pitrou

messages: + msg164655

components: + IO
stage: needs patch
2012-07-04 02:56:47apalalasetmessages: + msg164634
2012-07-04 02:55:08apalalacreate