PythonCharmers/python-future

Py2/3 support for Python 3 code using FileExistsError

Open

#251 aperta il 6 nov 2016

Vedi su GitHub
 (3 commenti) (2 reazioni) (0 assegnatari)Python (327 fork)batch import
0.20exceptionshelp wanted

Metriche repository

Star
 (1172 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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?

Guida contributor