[Python-3000] PEP: Information Attributes (original) (raw)
Josiah Carlson jcarlson at uci.edu
Tue May 1 09:24:30 CEST 2007
- Previous message: [Python-3000] PEP: Information Attributes
- Next message: [Python-3000] PEP: Information Attributes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Raymond Hettinger" <python at rcn.com> wrote:
Proto-PEP: Information Attributes (First Draft)
Proposal: Testing hasattr() is a broadly applicable and flexible technique that works well whenever the presence of a method has an unambiguous interpretation (i.e. hash for hashability, iter for iterability, len for sized containers); however, there are other methods with ambiguous interpretations that could be resolved by adding an information attribute.
To me, this seems more like traits/roles than ABCs. Though I haven't weighed in on either of them, generally I'm with Raymond and others in the whole "ABCs seem like overkill" perspective. As such, I'm -1 on ABCs, but +1 on the general idea of traits/roles - of which I would consider this PEP to be one.
My concern with Information Attributes is similar to my concern about ABCs; in order to state the information available from these information attributes, they need to be part of the class or instance. On built-in types, users would not be able to add things to classes or instances, as is the case with the numpy folks wanting to add 'ring' to integers.
While I've not seen a PEP for offering live traits/roles addition or removal, I suspect that it would involve weak key dictionaries adding traits to classes, and only allow hashable instances for single-object trait additions (depending on the kinds of traits/roles, it could probably be implemented as a dictionary of weak key sets). I would be +1 in this case, as it would offer most of the benefits of ABCs*, with none of the pre-implementation drawbacks.
- Josiah
- Related to ABCs is the issubclass and isinstance stuff that allows for proxy objects directly. Traits/roles could be massaged to do similar things, but using is... directly seems like it would perform this operation better. I'm not a real big
- Previous message: [Python-3000] PEP: Information Attributes
- Next message: [Python-3000] PEP: Information Attributes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]