[Python-Dev] When should pathlib stop being provisional?
ncoghlan at gmail.com
Wed Apr 6 02:23:00 EDT 2016
On 6 April 2016 at 15:59, Serhiy Storchaka <storchaka at gmail.com> wrote:
> On 06.04.16 08:52, Greg Ewing wrote:
>> Nick Coghlan wrote:
>>> The most promising option for that is probably "getattr(path, 'path',
>> Is there something seriously wrong with str(path)?
> What if path is None or bytes?
Or an int, float, list, dict, or arbitrary other object.
To be more explicit, the problem isn't what happens when the API doing
"str(path)" internally is used correctly, it's what happens when it's
used incorrectly: you end up proceeding with a nonsense string as your
path name, rather than failing early with TypeError or AttributeError.
Doing "getattr(path, 'path', path)" instead means that in the error
case (i.e. no "path" attribute), any existing argument checking is
still triggered normally.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev