PythonCharmers/python-future

Py2/3 support for Python 3 code using FileExistsError

Open

#251 创建于 2016年11月6日

在 GitHub 查看
 (3 评论) (2 反应) (0 负责人)Python (1,172 star) (327 fork)batch import
0.20exceptionshelp wanted

描述

I have code tested in Python 3 (3.5.2) that uses FileExistsError and have used pasteurize to attempt Py2/3 support. When I attempt to run the code under a Python 2.6.6 environment (installed importlib, unittest2, argparse beforehand), it encounters a NameError because of undefined FileExistsError:

Traceback (most recent call last):
  File "/home/dspruell/devel/project/env/bin/project-cmd", line 11, in <module>
    load_entry_point('project==0.2.4', 'console_scripts', 'project-cmd')()
  File "/home/dspruell/devel/project/env/lib/python2.6/site-packages/project/cli.py", line 86, in main
    except FileExistsError as e:
NameError: global name 'FileExistsError' is not defined

Following are the use in modules:

    try:
        args.func(args)
    except FileExistsError as e:
        parser.error('Refusing to clobber existing path ({err})'.format(err=e))
    try:
        os.makedirs(configdir)
    except FileExistsError as e:
        if not args.force:
            raise

For what it's worth, under Python 2.6 the exception that's raised in place of FileExistsError is OSError.

Is this something one should expect python-future to handle?

贡献者指南