[Python-Dev] Sets are mappings?
Nick Coghlan
ncoghlan at gmail.com
Thu Dec 22 09:57:39 CET 2005
Aahz wrote:
> On Wed, Dec 21, 2005, Michael Chermside wrote:
>> So I have a counter-proposal. Let's NOT create a hierarchy of abstract
>> base types for the elementary types of Python. (Even basestring feels
>> like a minor wart to me, although for now it seems like we need
>> it.) If the core problem is "how do you create a canonical ordering
>> for objects that survives serialization and deserialization into a
>> different VM?", then somehow abstract base types doesn't seem like
>> the most obvious solution. And if that's not the problem we're trying
>> to solve here, then what IS? Because I don't know of very many ACTUAL
>> (as opposed to theoretical) use cases for abstract base classes of
>> fundamental types.
>
> You've got a good point, but the documentation issue still exists; that's
> what I was more interested in. Clearly lists, tuples, and strings are
> sequences; clearly dicts are a mapping; the question is whether sets get
> tossed in with dicts. Overall, I think it's pretty clear that the answer
> is "no", particularly given that sets don't support __getitem__().
Like Aahz, my interest is more pedagogic than practical. Python's slightly
unusual in that the behaviour of sequences and multi-dimensional arrays (or
any kind of mapping, really) is more a matter of convention than anything
enforced by the language - whether or not a container understands slices or a
tuple of slices is the closest thing I've found to a reliable indicator as to
whether or not something is a sequence or multiarray rather than a simple mapping.
So in looking for a defining characteristic for those two terms (sequence, in
particular, is a term that gets thrown around a lot without being really well
defined), those are the main features I'd pick.
In practice, as MC said in his other email, "just try it and see what happens"
is generally a far better approach. To answer MC's other point in that email,
I actually agree it's perfectly possible to have a mapping which is not a
container, so the structure of the taxonomy should be eliminated entirely.
Whether or not something is a container and whether or not it is a mapping are
independent questions.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list