[Python-ideas] Better stdlib support for Path objects

MRAB python at mrabarnett.plus.com
Mon Oct 6 21:19:59 CEST 2014


On 2014-10-06 19:33, Barry Warsaw wrote:
> On Oct 06, 2014, at 11:29 AM, Guido van Rossum wrote:
>
>> Sounds like a plan. I'd like to see how hard it is in practice to
>> do the polymorphic return value thing.
>
> I'll do a limited experiment and post the results.
>
I wonder whether it might be cleaner to use a simple function for it,
something like:

def pathify(result_path, like=original_path):
     if isinstance(original_path, Path):
         return Path(result_path)

     if isinstance(original_path, str):
         return str(result_path)

     raise TypeError('original path must be a path or a string, not 
{!r}'.format(type(original_path)))


More information about the Python-ideas mailing list