Where a function has a single filename, such as open() or some of the os module functions, PyErr_SetFromErrnoWithFilename() is called, giving a third argument which is the filename. But, so that old code using in-place unpacking doesn't break, e.g.:
except OSError, (errno, strerror):
we hack args so that it only contains two items. This also means we need our own __str__() which prints out the filename when it was supplied.
(If a function has two filenames, such as rename(), symlink(), or copy(), PyErr_SetFromErrnoWithFilenameObjects() is called, which allows passing in a second filename.)
Types
OSErrorArgs[third] = tuple[errno: cint, strerror: string, filename: third, winerror: cint, filename2: string]
- Source Edit
Procs
proc init[E: PyOSError](self: ref E; args: OSErrorArgs)
- Source Edit
proc OSError_new[E: PyOSError](useWinError: bool; myerrno: cint; strerr: string; filename: string | int = ""; winerror: cint = 0; filename2 = ""; fillMsg: static[bool] = true): ref PyOSError
- may returns a subclass of OSError Source Edit
Templates
template oserror_use_init[E: PyOSError](self): bool
-
When __init__ is defined in an OSError subclass, we want any extraneous argument to __new__ to be ignored. The only reasonable solution, given __new__ takes a variable number of arguments, is to defer arg parsing and initialization to __init__.
But when __new__ is overridden as well, it should call our __new__ with the right arguments.
(see http://bugs.python.org/issue12555#msg148829 )
Source Edit