[Python-Dev] Alternative to more ABCs [was:] Iterable String Redux (aka String ABC)

Paul Moore p.f.moore at gmail.com
Sun Jun 1 15:57:55 CEST 2008


2008年6月1日 Guido van Rossum <guido at python.org>:
>> The case for String has already been made.
>> Actually I'm not sure. One you know that isinstance(x, String) is
> true, what can you assume you can do with x?
[...]
> Right. I'm now beginning to wonder what exactly you're after here --
> saying that something is an "X" without saying anything about an API
> isn't very useful. You need to have at least *some* API to be able to
> do anything with that knowledge.

Apologies to Raymond if I'm putting words into his mouth, but I think
it's more about *not* doing things with the type - a String is a
Sequence that we don't wish to iterate through (in the flatten case),
so the code winds up looking like
 for elem in seq:
 if isinstance(elem, Sequence) and not isinstance(elem, String):
 recurse into the element
 else:
 deal with the element as atomic
This implies that other "empty" abstract types aren't useful, though,
as they are not subclasses of anything else...
Paul.


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /