Am 21.06.2012 14:55, schrieb Nick Coghlan: > On Thu, Jun 21, 2012 at 9:26 PM, Christian Heimes <li...@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.from_errno(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 "<stdin>", line 1, in <module> 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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com