Path PEP: What should Path(None) do?

Peter Hansen peter at engcorp.com
Mon Jul 25 17:32:09 CEST 2005


Michael Hoffman wrote:
> Currently it returns Path('None'). This means I have to do a check on 
> input before pathifying it to make sure it is not None.
> 
> Perhaps it should throw ValueError?

Without checking, I suspect it is merely doing str(x) or unicode(x) on 
whatever is passed to it:

 >>> path(None)
path(u'None')
 >>> path(object())
path(u'<object object at 0x00AAB438>')
 >>> path(3.14159)
path(u'3.14159')

Therefore I think the question should be broadened beyond just None. 
Should Path(x) simply call str(x) on the object or should it raise 
ValueError or TypeError or something if it's not a basestring?

Given that pretty much *everything* in Python can have str() called on 
it, I think we should ask for a modicum of type-safety here and reject 
non-strings as input.

-Peter



More information about the Python-list mailing list