On Jan 30, 2013, at 2:01 PM, Cameron Simpson <c...@zip.com.au> wrote:

> Speaking for myself, I've been having some usefulness with making "URL"
> objects that are subclasses of str. That lets me pass them to all the
> things that already expect strs, while still having convenience methods.

str subclasses are problematic.  One issue is that it will still allow for 
invalid manipulations.  If you prohibit them, then manipulations that take 
multiple steps will be super inconvenient.  If you allow them, then you end up 
with half-formed values that will error out sometimes, or generate corrupt data 
that shouldn't be allowed to exist (trivial example; a NUL character in the 
middle of a file path).  Also, automatic coercion will sometimes surprise you 
and give you a value which is of the wrong type if you forget a method or two.

Also URL and file paths have a common interface, but are not totally the same.

Basically, everybody wants to say "composition is better than inheritance, 
except for *this* case, where inheritance seems super convenient".  That's how 
it gets you!  Inheritance _is_ super convenient, but it's also super confusing. 
 Resist the temptation :-).

Once again (I see my previous reply went straight to the sender, not the whole 
list) I recommend <https://launchpad.net/filepath> as an abstraction that has 
worked very well in a wide variety of situations.

-glyph
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to