classification
Title: PEP 3151 breaks backward compatibility: it should be documented
Type: behavior Stage: needs patch
Components: Documentation Versions: Python 3.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.araujo, flox, pitrou, vstinner
Priority: normal Keywords:

Created on 2011-10-28 14:18 by vstinner, last changed 2019-05-13 16:08 by mbussonn. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13287 merged mbussonn, 2019-05-13 16:08
Messages (4)
msg146562 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-28 14:18
The following example works on Python 2.7 and 3.2, but fails on Python 3.3:
-----------
import errno
import os

try:
    os.rmdir("testdir")
except:
    pass
os.mkdir("testdir")

try:
    try:
        os.mkdir("testdir")
    except IOError as exc:
        # If can't get proper access, then just forget about writing
        # the data.
        if exc.errno == errno.EACCES:
            pass
        else:
            raise
    except OSError as exc:
        # Probably another Python process already created the dir.
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise
except Exception:
    print("PEP 3151 broke backward compatibility on such pattern!")
-----------

I noticed the problem while reading the changeset e4d44c2e8e81.
msg146563 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-28 14:24
Why would you catch IOError after os.mkdir()?
msg146565 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-10-28 14:32
The first example was extracted from Lib/importlib/_bootstrap.py. The code was maybe wrong, I don't know.

Another example:
----------------------
import errno
import os

try:
    os.rmdir("testdir")
except:
    pass
os.mkdir("testdir")

try:
    try:
        #os.mkdir("testdir")
        open("NOT EXISTING FILENAME")
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise
    except IOError as exc:
        if exc.errno == errno.ENOENT:
            pass
        else:
            raise
except Exception:
    raise
    print("PEP 3151 broke backward compatibility on such pattern!")
----------------------

Uncomment mkdir() to test both paths.
msg152821 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-07 23:44
The code was fixed in importlib. I don't think that this borderline case should be documented anywhere, so I close this issue.
History
Date User Action Args
2019-05-13 16:08:51mbussonnsetpull_requests: + pull_request13197
2019-05-13 15:39:15vstinnersetpull_requests: - pull_request13194
2019-05-13 15:36:14mbussonnsetpull_requests: + pull_request13194
2012-02-07 23:44:28vstinnersetstatus: open -> closed
resolution: wont fix
messages: + msg152821
2011-11-12 13:48:19eric.araujosetnosy: + eric.araujo
2011-10-28 20:55:48floxsettype: behavior
stage: needs patch
2011-10-28 14:32:52vstinnersetmessages: + msg146565
2011-10-28 14:24:34pitrousetmessages: + msg146563
2011-10-28 14:18:50vstinnercreate