[Python-Dev] Add os.path.resolve to simplify the use of os.readlink (original) (raw)

Christian Heimes lists at cheimes.de
Thu Jun 21 15:04:17 CEST 2012


Am 21.06.2012 14:55, schrieb Nick Coghlan:

On Thu, Jun 21, 2012 at 9:26 PM, Christian Heimes <lists at cheimes.de> wrote:

BTW Is there a better way than raise OSError(errno.ELOOP, os.strerror(errno.ELOOP), filename) to raise a correct OSError with errno, errno message and filename? A classmethod like "OSError.fromerrno(errno, filename=None) -> proper subclass auf OSError with sterror() set" would reduce the burden for developers. PEP mentions the a similar idea at http://www.python.org/dev/peps/pep-3151/#implementation but this was never implemented. According to the C code, it should be working at least for recognised errno values: http://hg.python.org/cpython/file/009ac63759e9/Objects/exceptions.c#l890 I can't get it to trigger properly in my local build, though :(

Me neither with the one argument variant:

Python 3.3.0a4+ (default:c3616595dada+, Jun 19 2012, 23:12:25) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information.

import errno [73872 refs] type(OSError(errno.ENOENT)) <class 'OSError'> [73877 refs]

It works work two arguments but it doesn't set strerror and filename correctly:

exc = OSError(errno.ENOENT, "filename") [73948 refs] exc FileNotFoundError(2, 'filename') [73914 refs] exc.strerror 'filename' [73914 refs] exc.filename [73914 refs]

OSError doesn't accept keyword args:

OSError(errno.ENOENT, filename="filename") Traceback (most recent call last): File "", line 1, in TypeError: OSError does not take keyword arguments

How about adding keyword support to OSError and derive the strerror from errno if the second argument is not given?

Christian



More information about the Python-Dev mailing list