On Thu, May 22, 2008 at 12:21 AM, Brandon Mintern <firstname.lastname@example.org> wrote:
I would like to propose to change the built-in function "object" to
have the following syntax:
Return a new featureless object. object is a base for all new style
classes. It has the methods that are common to all instances of new
I agree this is a useful pattern. One thing I don't like about it is that:
looks very much like
object(x=1, y=2, z=3)
and I probably won't discover I've been given the wrong one until it's too late.
I think it can better addressed by implementing NamedList and NamedDict:
NamedList(typename, fieldnames[, optionalfields[, verbose]])
Returns a new list subclass named typename. The new subclass is used to create list-like objects that have fields accessible by attribute lookup as well as supporting other list operations. Instances of a NamedList may be created using a mixture of positional and keyword arguments. If optionalfields is not true, then the NamedList must always contain at least as many elements as the number of fields. If the NamedDict contains fewer elements than the number of fields, missing fields return None when accessed by attribute (a.third) and raise IndexError when accessed by index (a).
NamedDict(typename, fieldnames[, optionalfields[, verbose]])
Returns a new dict subclass named typename. The new subclass is used to
create dict-like objects that have fields accessible by attribute
lookup as well as supporting other dict operations. Instances of a NamedDict may be created using keyword arguments only. If optionalfields is not true, then the NamedDict must have a value for every field. If a NamedDict does not contain a field, accessing it returns None when
accessed by attribute (a.x) and raises KeyError when accessed using by key (a['x']).