On 6 April 2016 at 15:59, Serhiy Storchaka <storch...@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',
>>> 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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to