Armin Ronacher wrote: > Greg Ewing <greg.ewing <at> canterbury.ac.nz> writes: > > >> Well, I'm skeptical about the whole ABC thing in the >> first place -- it all seems very unpythonic to me. >> > I think it's very pythonic and the very best solution to interfaces *and* > duck typing. Not only does it extend duck-typing in a very, very cool way > but also does it provide a very cool way to get custom sets or lists going > with few extra work. Subclassing builtins was always very painful in the > past and many used the User* objects which however often broke because some > code did something like isinstance(x, (tuple, list)). Of course one could > argue that instance checking is the root of all evil but there are > situations where you have to do instance checking. And ABCs are the > perfect solution for that as they combine duck-typing and instance > checking. > > In my oppinion ABCs are the best feature of 2.6 and 3.0. > > >> But another way of thinking about it is that we >> already have an ABC of sorts for strings, and it's >> called basestring. It might be better to enhance >> that with whatever's considered missing than >> introducing another one. >> > basestring is not subclassable for example. Also it requires subclassing > which ABCs do not. > > I would be strongly +1 on a string ABC. Currently (to my knowledge) there is no way of using duck typing for built-in APIs that expect a string. How do I pass in an object to 'open' for example that isn't actually a string or subclass? >>> class X(object): ... def __unicode__(self): ... return 'fish' ... __str__ = __repr__ = __unicode__ ... >>> x = X() >>> open(x) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: coercing to Unicode: need string or buffer, X found >>> unicode(x) u'fish' Michael Foord > Regards, > Armin > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk > -- http://www.ironpythoninaction.com/ http://www.theotherdelia.co.uk/ http://www.voidspace.org.uk/ http://www.ironpython.info/ http://www.resolverhacks.net/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4