[Python-ideas] PEP: Extended stat_result (First Draft)
Antoine Pitrou
solipsis at pitrou.net
Tue May 7 11:13:45 CEST 2013
Le Mon, 06 May 2013 19:49:44 +0200,
Pieter Nagel <pieter at nagel.co.za> a écrit :
> On Mon, 2013-05-06 at 20:58 +0400, Oleg Broytman wrote:
>
> > I don't like the idea of changing os.stat() behaviour.
>
> I'm actually not proposing changing os.stat() behaviour, not for
> existing code. I'm proposing new optional behaviour that code could
> request.
>
> There is precedent for functions not raising exceptions, depending on
> the way they're called. dict.pop will raise KeyError, unless a default
> is given. str.encode can raise UnicodeErrors, depending on the value
> of the 'errors' parameter.
>
> In that light, a function that might or might not raise
> FileNotFoundError depending on how it was called is not that weird.
However, I should point out that FileNotFoundError is not the only
error that may be raised:
>>> os.stat("/proc/1/fd/1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: '/proc/1/fd/1'
(meaning that None may hide more information than you'd like)
Regards
Antoine.
More information about the Python-ideas
mailing list